SQLServer中查询表结构(表主键、列说明、列数据类型、所
有表名)的Sql语句
1、查询数据库中的所有表名称:
SELECT name FROM SysObjects Where XType='U'ORDER BY Name
结果:
2、查询数据库中指定表的表结构:
--快速查看表结构
SELECT CASE lorder =1THEN obj.name
ELSE''
END AS表名,
col.name AS列名 ,
ISNULL(ep.[value], '') AS列说明 ,
t.name AS数据类型 ,
col.length AS长度 ,
ISNULL(COLUMNPROPERTY(col.id, col.name, 'Scale'), 0) AS⼩数位数 ,
CASE WHEN COLUMNPROPERTY(col.id, col.name, 'IsIdentity') =1THEN'1'
ELSE''
END AS标识 ,
CASE WHEN EXISTS ( SELECT1
FROM    dbo.sysindexes si
INNER JOIN dbo.sysindexkeys sik ON si.id = sik.id
AND si.indid = sik.indid
INNER JOIN dbo.syscolumns sc ON sc.id = sik.id
lid = lid
INNER JOIN dbo.sysobjects so ON so.name = si.name
pe ='PK'
WHERE    sc.id = col.id
lid = lid ) THEN'1'
ELSE''
END AS主键 ,
CASE WHEN col.isnullable =1THEN'1'
ELSE''
END AS允许空 ,
, '') AS默认值
FROM    dbo.syscolumns col
LEFT JOIN dbo.systypes t pe = t.xusertype
inner JOIN dbo.sysobjects obj ON col.id = obj.id
pe ='U'
AND obj.status >=0
LEFT JOIN dbo.syscomments comm ON col.cdefault = comm.id
LEFT ded_properties ep ON col.id = ep.major_id
lid = ep.minor_id
AND ep.name ='MS_Description'
常用的sql查询语句有哪些LEFT ded_properties epTwo ON obj.id = epTwo.major_id
AND epTwo.minor_id =0
AND epTwo.name ='MS_Description'
WHERE  obj.name ='PkAutoInc'--表名
ORDER lorder ;
结果:
转⾃:wwwblogs/songxingzhu/p/5053149.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。