日期:2014-05-16  浏览次数:20443 次

超级有用的SQL语句(分析SQL SERVER 数据库表结构专用)
超级有用的SQL语句 (用于SQL SERVER 服务器)
超级有用的SQL语句 ,执行后返回的列分别是:表名、列名、列类型、列长度、列描述、是否主键,语句如下:

(分析SQL SERVER 数据库表结构专用)

以下是SQLSERVER2000


--------------------------------------------


Select Sysobjects.Name As 表名,
       Syscolumns.Name As 列名,
       Systypes.Name As 列类型,
       Syscolumns.Length As 列长度,
       Isnull(Sysproperties.Value, Syscolumns.Name) As 列说明,
       Case
         When Syscolumns.Name In
              (Select 主键 = A.Name
                 From Syscolumns A
                Inner Join Sysobjects B On A.Id = B.Id
                                       And B.Xtype = 'U'
                                       And B.Name <> 'Dtproperties'
                Where Exists (Select 1
                         From Sysobjects
                        Where Xtype = 'Pk'
                          And Name In
                              (Select Name
                                 From Sysindexes
                                Where Indid In
                                      (Select Indid
                                         From Sysindexkeys
                                        Where Id = A.Id
                                          And Colid = A.Colid)))
                  And B.Name = Sysobjects.Na