日期:2011-01-25 23:11:00 来源:本站整理
教您查询SQL字段属性的sql语句写法[MSSQL防范]
本文“教您查询SQL字段属性的sql语句写法[MSSQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
想要查看SQL字段属性,应当若何实现呢?下面为您介绍的就是查询SQL字段属性的sql语句写法,但愿对您学习SQL字段属性方面有所启迪.
以上是“教您查询SQL字段属性的sql语句写法[MSSQL防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
- SELECT sysobjects.name AS tableName, syscolumns.name AS field, properties.[value] AS fieldRemark, systypes.name AS type,
- syscolumns.length, ISNULL(COLUMNPROPERTY(syscolumns.id, syscolumns.name, 'Scale'), 0) AS [decimal], syscolumns.isnullable AS isnulls,
- CASE WHEN syscomments.text IS NULL THEN '' ELSE syscomments.text END AS [Default],
- CASE WHEN COLUMNPROPERTY(syscolumns.id, syscolumns.name, 'IsIdentity') = 1 THEN 'Y' ELSE 'N' END AS [id], CASE WHEN EXISTS
- (SELECT 1 FROM sysobjects WHERE xtype = 'PK' AND name IN (SELECT name FROM sysindexes WHERE indid IN (SELECT indid FROM sysindexkeys WHERE id = syscolumns.id AND colid = syscolumns.colid)))
- THEN 'Y' ELSE 'N' END AS PK FROM syscolumns INNER JOIN sysobjects ON sysobjects.id = syscolumns.id INNER JOIN
- systypes ON syscolumns.xtype = systypes.xtype LEFT OUTER JOIN sysproperties properties ON syscolumns.id = properties.id AND
- syscolumns.colid = properties.smallid LEFT OUTER JOIN sysproperties ON sysobjects.id = sysproperties.id AND
- sysproperties.smallid = 0 LEFT OUTER JOIN syscomments ON syscolumns.cdefault = syscomments.id
- WHERE (sysobjects.xtype = 'U') and systypes.name<>'sysname' order by sysobjects.name
- 利用:把这段代码拷贝到查询解析器内选中相关查询的数据库名便可.
- //符合我自己利用的查询数据库字典办法:SQL server 200
- SELECT sysobjects.name AS 表名,--获得数据库表名
- CASE WHEN EXISTS (SELECT 1 FROM sysobjects WHERE xtype = 'PK' AND name IN
- (SELECT name FROM sysindexes WHERE indid IN
- (SELECT indid FROM sysindexkeys WHERE id = syscolumns.id AND colid = syscolumns.colid)))
- THEN 'K' ELSE '' END AS PK,--能否是主键
- syscolumns.name AS 字段名,
- properties.[value] AS 字段描写,
- systypes.name AS 数据范例,
- syscolumns.length AS 长度,
- CASE syscolumns.isnullable WHEN '1' THEN '是' ELSE '否'END AS 答应为空,
- CASE WHEN syscomments.text IS NULL THEN '' ELSE syscomments.text END AS 默许值
- FROM syscolumns INNER JOIN
- sysobjects ON sysobjects.id = syscolumns.id INNER JOIN
- systypes ON syscolumns.xtype = systypes.xtype LEFT OUTER JOIN
- sysproperties properties ON syscolumns.id = properties.id AND
- syscolumns.colid = properties.smallid LEFT OUTER JOIN
- sysproperties ON sysobjects.id = sysproperties.id AND sysproperties.smallid = 0 LEFT OUTER JOIN
- syscomments ON syscolumns.cdefault = syscomments.id
- WHERE (sysobjects.xtype = 'U') and systypes.name<>'sysname'
- order by sysobjects.name desc
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论