How to get all the table fields and field descriptions in a database
Source: Internet
Author: User
Data | database | How to get all the table fields and field in the database Chinese description
The following information, through the csdn of a senior from the SQL moderator that get:
In SQL
SELECT
(case when A.colorder=1 then D.name else "end) N ' table name ',
A.colorder N ' field ordinal ',
A.name N ' field name ',
(Case when ColumnProperty (A.id,a.name, ' isidentity ') =1 then ' √ ' Else ' "end) N ' logo ',
(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 ' N ' primary key ',
B.name N ' type ',
A.length N ' occupies bytes ',
ColumnProperty (a.id,a.name, ' PRECISION ') as N ' length ',
IsNull (ColumnProperty (a.id,a.name, ' Scale '), 0) as N ' decimal digits ',
(case when a.isnullable=1 then ' √ ' else ') N ' Allow null ',
IsNull (E.text, ') N ' default value ',
IsNull (G.[value], ') as N ' field description '
--into # #tx
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 object_name (a.id), A.colorder
A word, cool, but also can save a lot of trouble when DD.
If you are not quite clear, you can put the above code on the SQL Query Analyzer to run a moment to know (of course, to open a database)
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