SQL queries all databases-table-table structure

Source: Internet
Author: User

1 --to query all database names in the database:2 SELECT *  fromMaster.. sysdatabasesORDER  byName3 --to query all table names in a database:4 Select *  fromsysobjectswhereType='U'5 --query Table Structure6 SELECT( Case  whenA.colorder=1  ThenD.nameElse NULL End) Table name,7 a.colorder field ordinal, a.name field name,8( Case  when ColumnProperty(A.id,a.name,'isidentity')=1  Then '√'Else "' End) identification,9( Case  when(SELECT Count(*) fromsysobjectsTen WHERE(Nameinch(SELECTName fromsysindexes One WHERE(ID=a.ID) and(indidinch   A(SELECTIndid fromSysindexkeys - WHERE(ID=a.ID) and(colidinch   -(SELECTColid fromsyscolumnsWHERE(ID=a.ID) and(Name=( a.name) ))))) the  and(xtype= 'PK'))>0  Then '√' Else "' End) primary key, B.name type, A.length takes up the number of bytes, - 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) allows null, - IsNull(E.text,"') Default value,IsNull(g.[value],' ') as [Description] +  fromsyscolumns a -  Left JoinSystypes b onA.xtype=B.xusertype + Inner Joinsysobjects D ona.ID=D.id andD.xtype='U'  andD.name<>'dtproperties'  A  Left Joinsyscomments E onA.cdefault=e.id at  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 - where - --b.name is not null -D.name='File_folder_name' --If you query only the specified table, add this condition - Order  byA.id,a.colorder

SQL queries all databases-table-table structure

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.