query table, field, type, whether primary key, length, decimal place, whether NULL is allowed, default value, and so on detailed query

Source: Internet
Author: User

Small fruit

SELECT    ( Case  whenA.colorder=1  ThenD.nameElse "' End) asTable name,--returns null if the table name is the sameA.colorder asfield ordinal, A.name asfield name, ( Case  when ColumnProperty(A.id,a.name,'isidentity')=1  Then '√'Else "' End) asidentification, ( Case  when(SELECT Count(*) fromsysobjects--Query primary Key                     WHERE(Nameinch                               (SELECTName fromsysindexesWHERE(ID=a.ID) and(indidinch                                       (SELECTIndid fromSysindexkeysWHERE(ID=a.ID) and(colidinch                                           (SELECTColid fromsyscolumnsWHERE(ID=a.ID) and(Name=( a.name) ))))) and(xtype= 'PK'))>0  Then '√' Else "' End) asPrimary KEY,--Query primary key endB.name astype, A.length asthe number of bytes consumed,ColumnProperty(A.id,a.name,'PRECISION') aslength,IsNull(ColumnProperty(A.id,a.name,' Scale'),0) asNumber of decimal digits, ( Case  whenA.isnullable=1  Then '√'Else "' End) asallow NULL,IsNull(E.text,"') asdefault value,IsNull(g.[value],"') asField Description fromSyscolumns A Left Joinsystypes b onA.xtype=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_idOrder  byA.id,a.colorder

Query table, field, type, whether primary key, length, decimal place, whether NULL is allowed, default value, and so on detailed 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.