Lists all SQL SERVER tables, field names, primary keys, types, lengths, decimal places, and more.

Source: Internet
Author: User
Tags end join sql table name
Server
SELECT

(case when A.colorder=1 then D.name else "end") Table name,

A.colorder field ordinal number,

A.name Field Name,

(Case when ColumnProperty (A.id,a.name, ' isidentity ') =1 then ' √ ' Else ' "End ') identifies,

(SELECT count (*)

From sysobjects

WHERE (name in

(SELECT name

From sysindexes

WHERE (id = a.id) and (Indid in

(SELECT indid

From Sysindexkeys

WHERE (id = a.id) and (Colid in

(SELECT colid

From syscolumns

WHERE (id = a.id) and (name = A.name)))) and

(xtype = ' PK ')) >0 Then ' √ ' Else ' ' end ' primary key,

B.name type,

A.length occupies a number of bytes,

ColumnProperty (a.id,a.name, ' PRECISION ') as length,

IsNull (ColumnProperty (a.id,a.name, ' Scale '), 0) as decimal digits,

(case when a.isnullable=1 then ' √ ' else ') allows NULL,

IsNull (E.text, ') default value,

IsNull (G.[value], ') as field 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 Sysproperties G

On a.id=g.id and a.colid = G.smallid

ORDER BY A.id,a.colorder


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.