-Query the database for all table name field names Description details

Source: Internet
Author: User

--Execute directly in the library where you need to query.

SELECT ( CaseWhen a.colorder=1Then D.nameElse NULLend) Table name, A.colorder field ordinal, a.name field name, ( CaseWhen ColumnProperty (A.id,a.name,'isidentity')=1Then'√'Else "'end) identification, ( CaseWhen (SELECT count (*) from sysobjects WHERE (nameinch(SELECT name from sysindexes WHERE (ID= a.ID) and (indidinch(SELECT indid from Sysindexkeys WHERE (ID= a.ID) and (colidinch(SELECT colid from syscolumns WHERE (ID= a.id) and (name =A.name))))) and (Xtype='PK')) >0Then'√' Else "'end) Primary key, B.name type, A.length occupies the number of bytes, ColumnProperty (A.id,a.name,'PRECISION') aslength, IsNull (ColumnProperty (A.id,a.name,' Scale'),0) asNumber of decimal digits, ( CaseWhen a.isnullable=1Then'√'Else "'end) allow null, IsNull (E.text,"') default value, IsNull (G.[value],' 'As [description] from syscolumns a left join systypes B on A.xtype=b.xusertype INNER join sysobjects D on a.id=d.id and D.xtype='U'and d.name<>'dtproperties'Left join syscomments e on A.cdefault=E.id left Join Sys.extended_properties G on a.id=G.MAJOR_ID and A.colid=g.minor_id left join Sys.extended_properties F on d.id=f.classand f.minor_id=0 whereB.name isNotNULL--where d.name='the table to query'--If you query only the specified table, add this condition to order by A.id,a.colorder

-Query the database for all table name field names Description details

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.