Get information about the field names, field descriptions, data types, primary keys, and other tables of the MSSQLSERVER database table

Source: Internet
Author: User
Tags mssqlserver

SQL script:

SELECTTableName= Case    whenA.colorder=1    ThenD.nameElse   "'   End,---table nameTableshowsthat= Case    whenA.colorder=1    Then   IsNull(F.value,"')Else   "'   End,---Table DescriptionTheserialnumberfield=A.colorder,---Field ordinalFieldName=A.name,---field nameIdentification= Case    when   ColumnProperty(A.id,a.name,'isidentity')=1    Then   '√'Else   "'   End, PrimaryKey= Case    when   exists(SELECT   1    fromsysobjectswhereXtype='PK'    andNameinch   (SELECTName fromsysindexesWHEREIndidinch(SELECTIndid fromSysindexkeysWHEREId=a.ID andColid=a.colid ))) Then   '√'   Else   "'   End,---Identify primary key[Type]=B.name,---Data typeTakeupthenumberofbytes=A.length,---Number of bytes occupied[Length]=ColumnProperty(A.id,a.name,'PRECISION'),---LengthDecimaldigits=IsNull(ColumnProperty(A.id,a.name,' Scale'),0),---Number of decimal digitsAllowEmpty= Case    whenA.isnullable=1    Then   '√'Else   "'   End,---Allow null[Default]=IsNull(E.text,"'),---Default ValueFieldsthat=IsNull(g.[value],"')---Field Description fromsyscolumns a Left   JoinSystypes b onA.xusertype=B.xusertypeInner   Joinsysobjects D ona.ID=D.id andD.xtype='U'    andD.name<>'dtproperties' Left   Joinsyscomments E onA.cdefault=e.id Left   JoinSys.extended_properties g ona.ID=g.major_id andA.colid=g.minor_id Left   JoinSys.extended_properties F onD.id=f.major_id andf.minor_id=0 whereD.name='Accounts_user'         --If you query only the specified table, add this conditionOrder    byA.id,a.colorder

Get information about the field names, field descriptions, data types, primary keys, and other tables of the MSSQLSERVER database table

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.