[SQL Server] querying user tables and table Structures

Source: Internet
Author: User
Query the structure of a user table: Select  

Table Name = Case   When A. colorder Is   Not   Null   Then D. Name Else   ''   End ,
FIELD No. = A. colorder,
Field name = A. Name,
Identifier = Case   When   Columnproperty (A. ID, A. Name, ' Isidentity ' ) = 1   Then   ' √ '   Else   ''   End ,
Primary Key = Case   When   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 ))) Then   ' √ '   Else   ''   End ,
Type = B. Name,
Bytes occupied = A. length,
Length = Columnproperty (A. ID, A. Name, ' Precision ' ),
Decimal places = Isnull ( Columnproperty (A. ID, A. Name, ' Scale ' ), 0 ),
Null allowed = Case   When A. isnullable = 1   Then   ' √ ' Else   ''   End ,
Default Value = Isnull (E. Text , '' ),
Field description = Isnull (G. [ Value ] , '' )

From Syscolumns Left   Join Policypes B On A. xtype = 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 Sysproperties g On A. ID = G. ID And A. colid = G. smallid

Where D. Name = ' Table1 ' -- Data Table Name
Order   By A. colorder -- Sort

query a user table: select table name = name from sysobjects where xtype = ' U ' and name ' dtproperties '

Related Article

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.