SQL Server obtains all table structures (including table names and fields)

Source: Internet
Author: User

1 SELECT( Case  whenA.colorder=1  ThenD.nameElse NULL End) Table name,2 a.colorder field ordinal, a.name field name,3( Case  when ColumnProperty(A.id,a.name,'isidentity')=1  Then '√'Else "' End) identification,4( Case  when(SELECT Count(*) fromsysobjects5 WHERE(Nameinch(SELECTName fromsysindexes6 WHERE(ID=a.ID) and(indidinch  7(SELECTIndid fromSysindexkeys8 WHERE(ID=a.ID) and(colidinch  9(SELECTColid fromsyscolumnsWHERE(ID=a.ID) and(Name=( a.name) )))))Ten  and(xtype= 'PK'))>0  Then '√' Else "' End) primary key, B.name type, A.length takes up the number of bytes, One ColumnProperty(A.id,a.name,'PRECISION') aslength, A IsNull(ColumnProperty(A.id,a.name,' Scale'),0) asNumber of decimal digits, ( Case  whenA.isnullable=1  Then '√'Else "' End) allows null, - IsNull(E.text,"') Default value,IsNull(g.[value],' ') as [Description] -  fromsyscolumns a the  Left JoinSystypes b onA.xtype=B.xusertype - Inner 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.class andf.minor_id=0 - whereB.name is  not NULL + --where d.name= ' table to query '--if you only query the specified table, add this condition A Order  byA.id,a.colorder

Get all database table names:

SELECT name from SysObjects Where xtype= ' U ' ORDER by name

  

SQL Server obtains all table structures (including table names and fields)

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.