SQL Server Export Table structure

Source: Internet
Author: User
Tags joins

Today, I'm going to tidy up a few databases, form a table structure document, convenient for later maintenance use.

Find a script on the internet is good, small changes to meet my requirements, execute the SQL script.

In the result can see the structure of all the database tables, this time as long as the full selection, and then right-click the property box, choose to save the results as, this time you just choose to export the CSV, and then create a new Excel table, select the data in the menu bar, and then choose from the text, the following people can self-processing.

SQL Server script:

SELECT Table name = case if A.colorder=1 then D.name Else ' End, table description = case when a.colorder=1 then IsNull (f.v Alue, ') Else ' End, field ordinal = a.colorder, field name = a.name, field description = IsNull (G.[value], '), identity = Cas e when ColumnProperty (A.id,a.name, ' isidentity ') =1 Then ' √ ' Else ' End, primary key = case when exists (SELECT 1 from Syso  bjects where xtype= ' PK ' and Parent_obj=a.id and name in (SELECT name from sysindexes Where indid in ( SELECT indid from Sysindexkeys WHERE id = a.id and colid=a.colid)) Then ' √ ' Else ' end, type = b.name, consume bytes Number = a.length, length = ColumnProperty (a.id,a.name, ' PRECISION '), number of decimal digits = IsNull (ColumnProperty (a.id,a.name, ' Scal E '), 0), allow null = case time a.isnullable=1 Then ' √ ' Else ' End, default value = IsNull (E.text, ') from syscolumns A  Left joins Systypes B on A.xusertype=b.xusertype Inner joins 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.major_id and f.minor_id=0--where d.name= ' OrderInf O '--if only the specified table is queried, add this condition to Order by A.id,a.colorder

SQL Server Export table structure

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.