查询sql2005&2008全部表信息

 1 如果是查询sql server 2000,把sys.extended_properties修改为SysProperties

 2 

 3 SELECT 

 4 表名       = CASE WHEN A.COLORDER=1 THEN D.NAME ELSE '' END,

 5 表说明     = CASE WHEN A.COLORDER=1 THEN ISNULL(F.VALUE,'') ELSE '' END,

 6 列序号   = A.COLORDER,

 7 列名     = A.NAME,

 8 标识       = CASE WHEN COLUMNPROPERTY( A.ID,A.NAME,'ISIDENTITY')=1 THEN ''ELSE '' END,

 9 主鍵       = CASE WHEN EXISTS(SELECT 1 FROM SYSOBJECTS WHERE XTYPE='PK' AND PARENT_OBJ=A.ID AND NAME IN (

10 SELECT NAME FROM SYSINDEXES WHERE INDID IN(

11 SELECT INDID FROM SYSINDEXKEYS WHERE ID = A.ID AND COLID=A.COLID))) THEN '' ELSE '' END,

12 类型       = B.NAME,

13 字节数 = A.LENGTH,

14 长度       = COLUMNPROPERTY(A.ID,A.NAME,'PRECISION'),

15 小数位数   = ISNULL(COLUMNPROPERTY(A.ID,A.NAME,'SCALE'),0),

16 允许空     = CASE WHEN A.ISNULLABLE=1 THEN ''ELSE '' END,

17 默认值     = ISNULL(E.TEXT,''),

18 字段说明   = ISNULL(G.[VALUE],'')

19 FROM 

20 SYSCOLUMNS A

21 LEFT JOIN 

22 SYSTYPES B 

23 ON 

24 A.XUSERTYPE=B.XUSERTYPE

25 INNER JOIN 

26 SYSOBJECTS D 

27 ON 

28 A.ID=D.ID  AND D.XTYPE='U' AND  D.NAME<>'DTPROPERTIES'

29 LEFT JOIN 

30 SYSCOMMENTS E 

31 ON 

32 A.CDEFAULT=E.ID

33 LEFT JOIN 

34 sys.extended_properties G 

35 ON 

36 A.ID=G.major_id AND A.COLID=G.minor_id  

37 LEFT JOIN 

38 sys.extended_properties F 

39 ON 

40 D.ID=F.major_id AND F.minor_id=0

41 ORDER BY 

42 A.ID,A.COLORDER

 

你可能感兴趣的:(sql2005)