Extremely useful SQL statements (dedicated for analysis of SQLSERVER database table structures)

Source: Internet
Author: User
Super useful SQL statements (for SQLSERVER server) super useful SQL statements, after execution, the returned columns are: Table Name, column name, column type, column length, column description, whether the primary key, the statement is as follows: (dedicated to analyzing the database table structure) the following is SQLSERVER2000SelectSysobjects. nameAs table

Extremely useful SQL statements (for SQL SERVER servers). After execution, the returned columns are: the following statements describe the table name, column name, column type, column length, column description, and whether the primary key is used: (used to analyze the SQL SERVER database table structure) SQLSERVER2000 Select Sysobjects. name As table

SuperUsefulSQLStatement(For SQL SERVER servers)
SuperUsefulSQLStatementThe columns returned after execution are: Table Name, column name, column type, column length, column description, and whether the column is a primary key,StatementAs follows:

(AnalysisSQL SERVERDatabaseTableStructureDedicated)

Below is SQLSERVER2000


Select Sysobjects. Name As table Name,
Syscolumns. Name As column Name,
Policypes. Name As column type,
Syscolumns. Length As column Length,
Isnull (Sysproperties. Value, Syscolumns. Name) As column description,
Case
When Syscolumns. Name In
(Select primary key = A. Name
From Syscolumns
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
Whether the End As primary key is used
From Sysobjects, policypes, 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 policypes. Xtype = Syscolumns. Xtype
And policypes. Name <> 'sysname'
And Sysobjects. Name Like '%'
Order By Sysobjects. Name, Syscolumns. Colid

The following are the versions of SQLSERVER 2005Statement

Select Sysobjects. Name As table Name,
Syscolumns. Name As column Name,
Policypes. Name As column type,
Syscolumns. Length As column Length,
Isnull (sys. extended_properties.Value, Syscolumns. Name) As column description,
Case
When Syscolumns. Name In
(Select primary key = A. Name
From Syscolumns
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
Whether the End As primary key is used
From Sysobjects, policypes, 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 policypes. Xtype = Syscolumns. Xtype
And policypes. Name <> 'sysname'
And Sysobjects. Name Like 'xjy %'
Order By Sysobjects. Name, Syscolumns. Colid

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.