首页 > 数据库 > mysql教程 > 获取SQL Server表字段的各种属性

获取SQL Server表字段的各种属性

WBOY
发布: 2016-06-07 17:44:44
原创
974 人浏览过

SELECT (CASE WHEN a.colorder=1 THEN d.name ELSE '' END) N'表名', a.colorder N'字段序号', a.name N'字段名', (CASE WHEN COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 THEN ''ELSE '' END) N'标识', (CASE WHEN (SELECT COUNT(*) FROM sysobjects WHER


SELECT
 (CASE WHEN a.colorder=1 THEN d.name ELSE '' END) N'表名',
 a.colorder N'字段序号',
 a.name N'字段名',
 (CASE WHEN COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 THEN '√'ELSE '' END) N'标识',
 (CASE WHEN (SELECT COUNT(*)
 FROM sysobjects
 WHERE (name in
           (SELECT name
          FROM sysindexes
          WHERE (id = a.id) AND (indid in
                    (SELECT indid
                   FROM sysindexkeys
                   WHERE (id = a.id) AND (colid in
                             (SELECT colid
                            FROM syscolumns
                            WHERE (id = a.id) AND (name = a.name))))))) AND
        (xtype = 'PK'))>0 THEN '√' ELSE '' END) N'主键',
 b.name N'类型',
 a.length N'占用字节数',
 COLUMNPROPERTY(a.id,a.name,'PRECISION') AS N'长度',
 ISNULL(COLUMNPROPERTY(a.id,a.name,'Scale'),0) AS N'小数位数',
 (CASE WHEN a.isnullable=1 THEN '√'ELSE '' END) N'允许空',
 ISNULL(e.text,'') N'默认值',
 ISNULL(g.[value],'') AS N'字段说明'
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   
WHERE
 d.name = 'SW_Project' --要查询的表
ORDER BY
 object_name(a.id), a.colorder

,香港虚拟主机,虚拟主机,香港服务器
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板