> 데이터 베이스 > MySQL 튜토리얼 > 超级有用的SQL语句(分析SQL SERVER 数据库表结构专用)

超级有用的SQL语句(分析SQL SERVER 数据库表结构专用)

WBOY
풀어 주다: 2016-06-07 15:14:47
원래의
1491명이 탐색했습니다.

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

超级有用的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.Name) Then
          1
         Else
          0
       End As 是否主键
  From Sysobjects, Systypes, Syscolumns
  Left Join Sysproperties On (Syscolumns.Id = Sysproperties.Id And
                             Syscolumns.Colid = Sysproperties.Smallid)
 Where (Sysobjects.Xtype = 'U' Or Sysobjects.Xtype = 'V')
   And Sysobjects.Id = Syscolumns.Id
   And Systypes.Xtype = Syscolumns.Xtype
   And Systypes.Name 'Sysname'
   And Sysobjects.Name Like '%'
 Order By Sysobjects.Name, Syscolumns.Colid

 


以下是SQLSERVER 2005版本的语句


Select Sysobjects.Name As 表名,
       Syscolumns.Name As 列名,
       Systypes.Name As 列类型,
       Syscolumns.Length As 列长度,
       Isnull(sys.extended_properties.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.Name) Then
          1
         Else
          0
       End As 是否主键
  From Sysobjects, Systypes, Syscolumns
  Left Join sys.extended_properties On (Syscolumns.Id = sys.extended_properties.major_id And
                             Syscolumns.Colid = sys.extended_properties.minor_id)
 Where (Sysobjects.Xtype = 'U' Or Sysobjects.Xtype = 'V')
   And Sysobjects.Id = Syscolumns.Id
   And Systypes.Xtype = Syscolumns.Xtype
   And Systypes.Name 'Sysname'
   And Sysobjects.Name Like 'XJY%'
 Order By Sysobjects.Name, Syscolumns.Colid

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿