小樱知识 > 生活常识 > 数据字典实例详解(做一个简单的网页查询数据库)

数据字典实例详解(做一个简单的网页查询数据库)

提问时间:2022-03-16 13:30:08来源:小樱知识网


数据字典可以帮助开发人员理解各个数据项目的类型、数值和它们与现实世界中的对象的关系。做数据库设计时数据字典是不可或缺的一部分,本文列出了几种常用数据的相关已有表获取数据字典的一些脚本,以下脚本仅仅测试了部分数据库版本,未必全部适配。

SqlServer2000:

        select           d.name as tname,        字段名 = a.name,        类型 = b.name,        长度 = columnproperty(a.id, a.name, 'PRECISION'),        小数位数 = isnull(columnproperty(a.id, a.name, 'Scale'),0),        允许空 = case when a.isnullable = 1 then '√' else '' end,        默认值 = isnull(e.text, ''),        字段说明 = isnull(g.[value], '')        from syscolumns a         left join systypes b on a.xtype = b.xusertype         inner join sysobjects d on a.id = d.id and d.xtype = 'U' and d.name <> 'dtproperties'        left join syscomments e on a.cdefault = e.id         left join sysproperties g on a.id = g.id and a.colid = g.smallid               order by a.id, a.colorder

SqlServer2005以上:

        select           d.name as tname,        字段名 = a.name,        类型 = b.name,        长度 = columnproperty(a.id, a.name, 'PRECISION'),        小数位数 = isnull(columnproperty(a.id, a.name, 'Scale'),0),        允许空 = case when a.isnullable = 1 then '√' else '' end,        默认值 = isnull(e.text, ''),        字段说明 = isnull(g.[value], '')        from syscolumns a         left join systypes b on a.xtype = b.xusertype         inner join sysobjects d on a.id = d.id and d.xtype = 'U' and d.name <> 'dtproperties'        left join syscomments e on a.cdefault = e.id         left join sys.extended_properties g on a.id = g.major_id and a.colid = g.minor_id         order by a.id, a.colorder  

Oracle:

        select           a.table_name as tname,        a.column_name as 字段名,         a.data_type as 类型,        a.data_length as 长度,        case when a.data_scale = null then 0 else a.data_scale end as 小数位数,        case when a.nullable = 'Y' then '√' else '' end as 允许空,        a.data_default as 默认值,        case when b.comments = null then '' else b.comments end as 字段说明        from user_tab_columns A         left join user_col_comments B on A.table_name = B.table_name         and A.column_name = B.column_name         order by column_id   

MySql:

        select           a.table_name as tname,          a.column_name as 字段名,           a.data_type as 类型,          a.character_maximum_length as 长度,          a.numeric_scale as 小数位数,          case when a.is_nullable = 'YES' then '√' else '' end as 允许空,          a.column_default as 默认值,          column_comment as 字段说明        from information_schema.columns A         order by ordinal_position 

达梦6:

        select           d.name as tname,        a.name as 字段名,        a.TYPE as 类型,        a.LENGTH as 长度,        a.SCALE as 小数位数,        case when a.NULLABLE = 'Y' then '√' else '' end as 允许空,        isnull(a.DEFVAL, '') as 默认值,        isnull(a.resvd5, '') as 字段说明        from SYSDBA.SYSCOLUMNS a         inner join SYSDBA.SYSTABLES d on a.id = d.id and d.type = 'U'        order by a.id, a.colid   

达梦7:

        select           a.table_name as tname,        a.column_name as 字段名,         a.data_type as 类型,        a.data_length as 长度,        case when a.data_scale = null then 0 else a.data_scale end as 小数位数,        case when a.nullable = 'Y' then '√' else '' end as 允许空,        a.data_default as 默认值,        case when b.comments = null then '' else b.comments end as 字段说明        from user_tab_columns A         left join user_col_comments B on A.table_name = B.table_name         and A.column_name = B.column_name         order by column_id      

人大金仓:

        select           a.table_name as tname,        a.column_name as 字段名,         a.data_type as 类型,        a.data_length as 长度,        case when a.data_scale = null then 0 else a.data_scale end as 小数位数,        case when a.nullable = 'Y' then '√' else '' end as 允许空,        a.data_default as 默认值,        '' as 字段说明 --相关的字段说明没有找到怎么获取        from user_tab_columns A         order by column_id   

当前的数据库设计更倾向于直接在数据库里建数据字典表,就不存在数据库兼容适配的问题了。

以上内容就是为大家推荐的数据字典实例详解(做一个简单的网页查询数据库)最佳回答,如果还想搜索其他问题,请收藏本网站或点击搜索更多问题

内容来源于网络仅供参考
二维码

扫一扫关注我们

版权声明:所有来源标注为小樱知识网www.cnfyy.com的内容版权均为本站所有,若您需要引用、转载,只需要注明来源及原文链接即可。

本文标题:数据字典实例详解(做一个简单的网页查询数据库)

本文地址:https://www.cnfyy.com/shcs/119358.html

相关文章