日期:2014-05-17 浏览次数:20570 次
SELECT
Sysobjects.name AS [表名],
syscolumns.name AS [列名],
systypes.name AS [数据类型],
syscolumns.length AS [字段长度],
sys.extended_properties.[value] AS [字段描述],
syscomments.text AS [默认值],
CASE syscolumns.isnullable WHEN ‘1‘ THEN ‘Y‘ ELSE ‘N‘ END AS [是否允许空值],
ISNULL(COLUMNPROPERTY(syscolumns.id, syscolumns.name, ‘Scale‘), 0) AS [小数位数],
COLUMNPROPERTY(syscolumns.id, syscolumns.name, ‘IsIdentity‘) 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 ‘√‘ ELSE ‘‘ END AS [主键]
FROM syscolumns
INNER JOIN systypes
ON syscolumns.xtype = systypes.xtype
LEFT JOIN sysobjects ON syscolumns.id = sysobjects.id
LEFT OUTER JOIN sys.extended_properties ON
( sys.extended_properties.minor_id = syscolumns.colid
AND sys.extended_properties.major_id = syscolumns.id)
LEFT OUTER JOIN syscomments ON syscolumns.cdefault = syscomments.id
WHERE (systypes.name <> ‘sysname‘)
-- AND syscolumns.id IN (SELECT id FROM SYSOBJECTS WHERE xtype = ‘U‘ AND NAME = ‘表名‘) --仅查某表,否则注释掉本行为全库
ORDER BY [表名],[列名]
跟2005的不一样?
select name from sysobjects where xtype='u'
select name from sys.tables