码迷,mamicode.com
首页 > 其他好文 > 详细

查看库中表的主键,标识列,计算列,字段类型,允许空,默认值等属性

时间:2016-06-13 15:03:42      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

查看库中表的主键,标识列,计算列,字段类型,允许空,默认值等属性

            SELECT
            [表名]=CASE WHEN T.column_id = 1 THEN OBJECT_NAME(T.object_id) ELSE ‘‘ END ,
            [字段编号]=T.column_id,
            [字段名]=T.name,
            [主键]=case when exists(SELECT 1 FROM sys.key_constraints  where type=PK and object_id=T.OBJECT_ID) THEN  ELSE ‘‘ END,
            [标识列]=CASE T.is_identity  WHEN 1 THEN  ELSE ‘‘ END,
            [计算列]=CASE T.is_computed WHEN 1 THEN  ELSE ‘‘ END,
            [字段类型]=(SELECT name FROM sys.types WHERE user_type_id = T.user_type_id),
            [字段长度]= T.PRECISION,
            [小数位] = T.Scale,
            [允许空] = CASE T.is_nullable  WHEN 1 THEN  ELSE ‘‘ END,
            [默认值]= ISNULL((SELECT definition from sys.default_constraints where object_id = T.default_object_id),‘‘),
            [字段说明]=(SELECT VALUE FROM sys.extended_properties WHERE major_id = T.OBJECT_ID AND minor_id  =T.column_id)
            FROM sys.COLUMNS T
            INNER JOIN sys.objects O ON T.object_id = O.object_id AND O.type = U
            WHERE RIGHT(OBJECT_NAME(T.object_id),3) <> Log AND OBJECT_NAME(T.object_id) <>AuditDDLEvents AND OBJECT_NAME(T.object_id) <>dtproperties
            ORDER BY OBJECT_NAME(T.object_id),T.column_id

 

查看库中表的主键,标识列,计算列,字段类型,允许空,默认值等属性

标签:

原文地址:http://www.cnblogs.com/davidhou/p/5580310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!