[SQL脚本]数据字典
2011-06-10 10:10
239 查看
select
[表名]=c.Name,
[表说明]=isnull(f.[value],''),
[列名]=a.Name,
[列序号]=a.Column_id,
[标识]=case when is_identity=1 then '√' else '' end,
[主键]=case when exists(select 1 from sys.objects x join sys.indexes y on x.Type=N'PK' and x.Name=y.Name
join sysindexkeys z on z.ID=a.Object_id and z.indid=y.index_id and z.Colid=a.Column_id)
then '√' else '' end,
[类型]=b.Name,
[字节数]=case when a.[max_length]=-1 and b.Name!='xml' then 'max/2G'
when b.Name='xml' then '2^31-1字节/2G'
else rtrim(a.[max_length]) end,
[长度]=case when ColumnProperty(a.object_id,a.Name,'Precision')=-1 then '2^31-1'
else rtrim(ColumnProperty(a.object_id,a.Name,'Precision')) end,
[小数]=isnull(ColumnProperty(a.object_id,a.Name,'Scale'),0),
[是否为空]=case when a.is_nullable=1 then '√' else '' end,
[列说明]=isnull(e.[value],''),
[默认值]=isnull(d.text,'')
from
sys.columns a
left join
sys.types b on a.user_type_id=b.user_type_id
inner join
sys.objects c on a.object_id=c.object_id and c.Type='U'
left join
syscomments d on a.default_object_id=d.ID
left join
sys.extended_properties e on e.major_id=c.object_id and e.minor_id=a.Column_id and e.class=1
left join
sys.extended_properties f on f.major_id=c.object_id and f.minor_id=0 and f.class=1
order by [表名],[列名]
[表名]=c.Name,
[表说明]=isnull(f.[value],''),
[列名]=a.Name,
[列序号]=a.Column_id,
[标识]=case when is_identity=1 then '√' else '' end,
[主键]=case when exists(select 1 from sys.objects x join sys.indexes y on x.Type=N'PK' and x.Name=y.Name
join sysindexkeys z on z.ID=a.Object_id and z.indid=y.index_id and z.Colid=a.Column_id)
then '√' else '' end,
[类型]=b.Name,
[字节数]=case when a.[max_length]=-1 and b.Name!='xml' then 'max/2G'
when b.Name='xml' then '2^31-1字节/2G'
else rtrim(a.[max_length]) end,
[长度]=case when ColumnProperty(a.object_id,a.Name,'Precision')=-1 then '2^31-1'
else rtrim(ColumnProperty(a.object_id,a.Name,'Precision')) end,
[小数]=isnull(ColumnProperty(a.object_id,a.Name,'Scale'),0),
[是否为空]=case when a.is_nullable=1 then '√' else '' end,
[列说明]=isnull(e.[value],''),
[默认值]=isnull(d.text,'')
from
sys.columns a
left join
sys.types b on a.user_type_id=b.user_type_id
inner join
sys.objects c on a.object_id=c.object_id and c.Type='U'
left join
syscomments d on a.default_object_id=d.ID
left join
sys.extended_properties e on e.major_id=c.object_id and e.minor_id=a.Column_id and e.class=1
left join
sys.extended_properties f on f.major_id=c.object_id and f.minor_id=0 and f.class=1
order by [表名],[列名]
相关文章推荐
- 根据库中的表自动生成数据字典的T-SQL脚本 ---转
- 根据库中的表自动生成数据字典的T-SQL脚本
- 【greenplum】greenplum 数据字典实践--通过sql脚本查询表结构,拼装建表语句
- 有用的数据SQL脚本(做数据字典比较有用哦)
- 深入了解Oracle数据字典升级脚本catupgrd.sql调用过程
- SqlServer2005(2000)数据库字典,将表数据生成SQL脚本的存储过程 (转)
- 利用sql脚本把数据字典导出
- 深入了解Oracle数据字典升级脚本catupgrd.sql调用过程
- 用Sql语句生成Sqlserver数据字典(备份)
- 用脚本生成授权语句,输入参数包括用户名、IP、数据库名、要求的权限列表,输出为授权sql
- 利用存储过程导出数据到sql脚本
- SQL获取指定数据表所有字段类型和精度脚本
- SQLServer 工具箱v1.3(SQL脚本排序,日志清除,数据导入导出)附完整源代码
- SQL 备份数据 脚本 -添加到作业 步骤里面 可删除历史天文件
- 将表数据生成SQL脚本的存储过程
- 数据SQL脚本自动转换成javaBean代码的实现
- SQl 中几种常用的数据字典SQL
- 查看数据库和数据字典的SQL
- 【实用SQL脚本】生成数据发布的INSERT语句 推荐
- 全国省市区(县)数据以及位置坐标 包含SQL脚本