SQL Server field Description Query (table basic information query)

Source: Internet
Author: User

--Quick View of table structure (more comprehensive)SELECT   Case  whenCol.colorder= 1  ThenObj.nameELSE "'             END  astable name, Col.colorder asserial number, Col.name ascolumn name,ISNULL(ep.[value],"') ascolumn description, T.name asdata type, Col.length aslength,ISNULL(ColumnProperty(Col.id, Col.name,' Scale'),0) asNumber of decimal digits, Case  when ColumnProperty(Col.id, Col.name,'isidentity')= 1  Then '√'             ELSE "'        END  asidentification, Case  when EXISTS(SELECT   1                            fromdbo.sysindexes siINNER JOINDbo.sysindexkeys Sik onSi.id=sik.id andSi.indid=Sik.indidINNER JOINDbo.syscolumns SC onSc.id=sik.id andSc.colid=Sik.colidINNER JOINDbo.sysobjects so onSo.name=Si.name andSo.xtype= 'PK'                           WHERESc.id=col.id andSc.colid=Col.colid) Then '√'             ELSE "'        END  asprimary KEY, Case  whenCol.isnullable= 1  Then '√'             ELSE "'        END  asallow NULL,ISNULL(Comm.text,"') asDefault Value fromDbo.syscolumns Col Left  JOINDbo.systypes T onCol.xtype=T.xusertypeInner JOINDbo.sysobjects obj onCol.id=obj.id andObj.xtype= 'U'                                          andObj.status>= 0         Left  JOINDbo.syscomments Comm onCol.cdefault=comm.id Left  JOINSys.extended_properties EP onCol.id=ep.major_id andCol.colid=ep.minor_id andEp.name= 'ms_description'         Left  JOINSys.extended_properties Eptwo onObj.id=eptwo.major_id andeptwo.minor_id= 0                                                          andEptwo.name= 'ms_description'WHEREObj.name= 'egression'--Table nameORDER  byCol.colorder;

The code above applies to the SQL Server database, only changes the table name and executes the code to get the basic information for the table (code from Network: http://blog.csdn.net/changhong009/article/details/29587063)

Here is the simple code (not tested)

SELECTT.[name]  asTable name, C.[name]  asField name,cast(ep.[value]    as varchar( -)) as [Field Description]   fromSys.tables asTINNER JOINsys.columns asC onT.object_id =C.object_id    Left JOINSys.extended_properties asEP onep.major_id=C.object_id  andep.minor_id=c.column_idWHEREEp.class=1    andT.name='TableName'

SQL Server field Description Query (table basic information query)

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.