sqlserver 数据字典

来源:互联网 发布:steam淘宝黑卡 编辑:程序博客网 时间:2024/04/29 04:56

数据字典:数据库各表的字段说明、类型、主键、长度...一系列的描述,使用数据字典非常有利于团队开发。

以下sql语句就是查询某个数据库的所有表的各字段信息的详细描述:

如,你有一个abc的数据库,在abc上右键“新建查询”,把下面的sql粘贴上去,运行即可

select     [表名]=c.Name,    [表说明]=isnull(f.[value],''),    [列名]=a.Name,    [列说明]=isnull(e.[value],''),    [列序号]=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(d.text,'')    from     sys.columns aleft join    sys.types b on a.user_type_id=b.user_type_idinner 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.IDleft 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


如果你的数据库中的表特别多,你只想查询数据库abc中某个具体的表如“students“,那么你需要在上述sql语句中加上如下sql代码:

where c.name='students'

如果你查询的结果是下面的样子




列说明为空的,那么你就要去到具体的表 “右键”--“设计”,在右侧“列属性”中找到 “说明”,在说明的右侧填写该表某字段的说明(如下图)


每个字段都填写好后,保存表的修改,刷新一下,再次执行上面的sql,是不是就OK了呢。


这里上面的sql是从http://blog.csdn.net/roy_88/article/details/1914264 这里摘抄下来的,因为脑子比较笨,容易忘事,就简单的做了一个记录,仅个人记录。




0 0
原创粉丝点击