SELECT
Sysobjects.name as table name,--------------as function: An alias for the field
--sysproperties. [Value] As table description,----------[] square brackets function: In order to avoid conflicts with keywords
Syscolumns.name as field name,
--properties. [Value] As field description,
Systypes.name as field type,
Syscolumns.length as field length,
ISNULL (ColumnProperty (syscolumns.id, syscolumns.name, ' scale '), 0) as decimal digits,
--isnull---(data to be measured, return value). Returns the return value when the data to be measured is null, back to the data to be measured when the big policy data is non-null
Case when Syscolumns.isnullable=0
Then '
ELSE ' √ '
If END as is empty,
Case if Syscomments.text is NULL
Then ' ELSE syscomments.text
END as default value,
Case when ColumnProperty (Syscolumns.id, Syscolumns.name, ' isidentity ') = 1
Then ' √ ' ELSE '
END as Increment field,
Case if Sysindexes.name is NULL
Then '
ELSE Sysindexes.name
END as index name,
Case if Sysindexkeys.keyno is NULL
Then '
ELSE CONVERT (VARCHAR), Sysindexkeys.keyno
END as index position,
Case when sysindexes.indid=1
Then ' clustered index '
When Sysindexes.indid>1 and sysindexes.indid<>255
Then ' nonclustered index '
When Sysindexes.indid is NULL
Then '
ELSE
Other
END as index type,
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 = syscolumns.id and colid = syscolumns.colid)))
Then ' √ ' ELSE '
END as primary key,
Case if Sysforeignkeys.constid is NULL
Then '
ELSE ' √ '
END as external health
From syscolumns--Data table field
INNER JOIN sysobjects--data object
On sysobjects.id = Syscolumns.id
INNER JOIN systypes--Data type
On syscolumns.xtype = Systypes.xtype
Left OUTER JOIN syscomments--Comment information
On syscolumns.cdefault = Syscomments.id
Left OUTER JOIN Sysindexkeys--Information about keys or columns in an index
On sysindexkeys.id = Syscolumns.id
and sysindexkeys.colid = Syscolumns.colid
Left OUTER JOIN sysindexes--Database Index Table
On sysindexes.id = Sysindexkeys.id
and Sysindexes.indid = Sysindexkeys.indid
Left OUTER JOIN Sysforeignkeys
On Sysforeignkeys.fkeyid = Syscolumns.id
and Sysforeignkeys.fkey = Syscolumns.colid
WHERE (sysobjects.xtype = ' U ')
ORDER BY Sysobjects.id,syscolumns.colid
Get full SQL for SQL Server data dictionary