Obtain the SQL Server table name and field information.

Source: Internet
Author: User

--- Table field name --

Select B. [name] As 'column name', C. [name] As 'data type', B. length as 'length', D. value as 'description' 'from sysobjects
Left join syscolumns B on A. [ID] = B. [ID]
Left join policypes C on B. xtype = C. xtype and B. xusertype = C. xusertype
Left join sysproperties D on B. [ID] = D. [ID] and B. [colid] = D. [smallid]
Where a. xtype = 'U' and A. type = 'U' and A. [name] = 'your table name'

--- All table field names --
Select

(Case when a. colorder = 1 then D. Name else ''end) Table Name,

A. Serial number of the colorder field,

A. Name field name,

(Case when columnproperty (A. ID, A. Name, 'isidentity ') = 1 then' √ 'else' end) ID,

(Case when (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 the number of bytes,

Columnproperty (A. ID, A. Name, 'precision ') as length,

Isnull (columnproperty (A. ID, A. Name, 'Scale'), 0) as decimal places,

(Case when a. isnullable = 1 then '√ 'else'' End) Allow null,

Isnull (E. Text, '') default value,

Isnull (G. [value], '') as field description

From syscolumns a left join policypes 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.