(Transfer) obtain information from user tables

xiaoxiao2021-03-06  13

SELECT

Table name = Case When a.colorder = 1 Then D.Name Else '' end,

Table Description = Case When a.colorder = 1 Then ISNULL (F.Value, '') Else '' end,

Field serial number = a.colorder,

Field name = a.name,

Logo = Case When ColumnProperty (A.ID, A.NAME, 'ISIDENTITY') = 1 TEN '√'lse' 'end,

Primary key = Case When exists (SELECT 1 from sysobjects where xtype = 'pk' and name in)

Select Name from sysindexes where indid in

Select Indid from sysindexkeys where id = a.id and color = a.colid

))) The '√' else '' end,

Type = B.Name,

Number of bytes = a.length,

Length = ColumnProperty (A.ID, A.Name, 'Precision'),

Digital digits = ISNULL (ColumnProperty (A.ID, A.NAME, 'Scale'), 0),

Allow empty = Case When a.isnullable = 1 Then '√'lse' 'End,

Default = Isnull (E.Text, ''),

Field Description = ISNULL (g. [Value], '')

From syscolumns a

Left join systemypes b on a.xUsertype = 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

LEFT JOIN SYSPROPERTIES F on D.ID = f.id and f.smallid = 0

--where d.name = 'table_name' - If you want to query a specific Table, add this sentence

Order by a.id, a.colorder

转载请注明原文地址:https://www.9cbs.com/read-49766.html

New Post(0)