获取SQL Server 数据库结构

 
SELECT
     表名       = CASE WHEN A.COLORDER = 1 THEN D.NAME ELSE '' END,
     表说明     = CASE WHEN A.COLORDER = 1 THEN ISNULL(F.VALUE,'') ELSE '' END,
     字段序号   = A.COLORDER,
     字段名     = A.NAME,
     字段说明   = ISNULL(G.VALUE,''),
     标识       = CASE WHEN COLUMNPROPERTY( A.ID,A.NAME,'IsIdentity') = 1 THEN '是'ELSE '否' END,
     主键       = CASE WHEN EXISTS(
					SELECT 1 FROM SYSOBJECTS WHERE XTYPE = 'PK' AND PARENT_OBJ = A.ID AND NAME IN (
                      SELECT NAME FROM SYSINDEXES WHERE INDID IN(SELECT INDID FROM SYSINDEXKEYS WHERE ID = A.ID AND COLID = A.COLID)
					)
				  ) THEN '是' ELSE '否' END,
     类型       = B.NAME,
     占用字节数 = A.LENGTH,
     长度       = COLUMNPROPERTY(A.ID,A.NAME,'PRECISION'),
     小数位数   = ISNULL(COLUMNPROPERTY(A.ID,A.NAME,'SCALE'),0),
     允许空     = CASE WHEN A.ISNULLABLE = 1 THEN '是'ELSE '否' END,
     默认值     = ISNULL(E.TEXT,'')
 FROM SYSCOLUMNS A
 LEFT JOIN SYSTYPES B ON A.XUSERTYPE = 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.MAJOR_ID
 LEFT JOIN SYS.EXTENDED_PROPERTIES F ON D.ID = F.MAJOR_ID AND F.MAJOR_ID = 0 --where d.name='OrderInfo'    --如果只查询指定表,加上此条件
 Order By
 A.ID,
 A.COLORDER

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值