经过对SQLServer2000系统表的分析,写出了以下两个SQL语句。可以把这两个语句分别建为两个“视图”,方便查看用户数据表和字段的信息。
1、列出所有的用户数据表:
SELECT TOP 100 PERCENT o.name AS 表名
FROM dbo.syscolumns c INNER JOIN
dbo.sysobjects o ON o.id = c.id AND objectproperty(o.id, N'IsUserTable') = 1 AND
o.name <> 'dtproperties' LEFT OUTER JOIN
dbo.sysproperties m ON m.id = o.id AND m.smallid = c.colorder
WHERE (c.colid = 1)
ORDER BY o.name, c.colid2、列出所有的用户数据表及其字段信息:
SELECT TOP 100 PERCENT c.colid AS 序号, o.name AS 表名, c.name AS 列名,
t.name AS 类型, c.length AS 长度, c.isnullable AS 允许空,
CAST(m.[value] AS Varchar(100)) AS 说明
FROM dbo.syscolumns c INNER JOIN
dbo.sysobjects o ON o.id = c.id AND objectproperty(o.id, N'IsUserTable') = 1 AND
o.name <> 'dtproperties' INNER JOIN
dbo.systypes t ON t.xusertype = c.xusertype LEFT OUTER JOIN
dbo.sysproperties m ON m.id = o.id AND m.smallid = c.colorder
ORDER BY o.name, c.colid你如果有更好的方法,请交流一下:)
----作者:夏春涛 Email:
xChuntao@163.com QQ:23106676 ----