Copy codeThe Code is as follows:
-- SQL Server 2000
SELECT a. name AS field name, CASE WHEN EXISTS
(SELECT 1
FROM sysobjects
WHERE xtype = 'pk' AND parent_obj = a. id AND name IN
(SELECT name
FROM sysindexes
WHERE indid IN
(SELECT indid
FROM sysindexkeys
WHERE id = a. id AND colid = a. colid )))
THEN '1' ELSE '0' end as primary key, case when columnproperty (a. id, a. name,
'Isidentity ') = 1 then'1' ELSE '0' end as id, B. name AS type,
A. length AS occupies the number of bytes, COLUMNPROPERTY (a. id, a. name, 'precision ') AS length,
A. xscale AS decimal, a. isnullable AS can be empty, ISNULL (e. text, '') AS default value, ISNULL (g. [value],
'') AS field description
FROM syscolumns a LEFT OUTER JOIN
Policypes B ON a. xusertype = B. xusertype INNER JOIN
Sysobjects d ON a. id = d. id AND d. xtype = 'U' AND
D. name <> 'dtproperties' LEFT OUTER JOIN
Syscomments e ON a. cdefault = e. id LEFT OUTER JOIN
Sysproperties g ON a. id = g. id AND a. colid = g. smallid LEFT OUTER JOIN
Sysproperties f ON d. id = f. id AND f. smallid = 0
WHERE (d. name = 'table name ')
-- 2. SQL SERVER 2005
SELECT CASE WHEN EXISTS
(SELECT 1
FROM sysobjects
WHERE xtype = 'pk' AND parent_obj = a. id AND name IN
(SELECT name
FROM sysindexes
WHERE indid IN
(SELECT indid
FROM sysindexkeys
WHERE id =. id AND colid =. colid) THEN '1' ELSE '0' end as 'key', case when columnproperty (. id,. name,
'Isidentified') = 1 then'1' ELSE '0' end as 'identifier',. name AS ColName, c. name AS TypeName,. length AS 'byte', COLUMNPROPERTY (. id,. name,
'Precision ') AS 'length',. xscale,. isnullable, ISNULL (e. text, '') AS 'default', ISNULL (p. value, '') AS 'comment'
FROM sys. syscolumns AS a INNER JOIN
Sys. sysobjects AS B ON a. id = B. id INNER JOIN
Sys. policypes AS c ON a. xtype = c. xtype LEFT OUTER JOIN
Sys. syscomments AS e ON a. cdefault = e. id LEFT OUTER JOIN
Sys. extended_properties AS p ON a. id = p. major_id AND a. colid = p. minor_id
WHERE (B. name = 'keyfactory ') AND (c. status <> '1 ')
-- B. name = 'keyfactory ', 'keyfactory' the data table you want to query.
-- 2. SQL SERVER 2005
SELECT CASE WHEN EXISTS
(SELECT 1
FROM sysobjects
WHERE xtype = 'pk' AND parent_obj = a. id AND name IN
(SELECT name
FROM sysindexes
WHERE indid IN
(SELECT indid
FROM sysindexkeys
WHERE id =. id AND colid =. colid) THEN '1' ELSE '0' end as 'key', case when columnproperty (. id,. name,
'Isidentified') = 1 then'1' ELSE '0' end as 'identifier',. name AS ColName, c. name AS TypeName,. length AS 'byte', COLUMNPROPERTY (. id,. name,
'Precision ') AS 'length',. xscale,. isnullable, ISNULL (e. text, '') AS 'default', ISNULL (p. value, '') AS 'comment'
FROM sys. syscolumns AS a INNER JOIN
Sys. sysobjects AS B ON a. id = B. id INNER JOIN
Sys. policypes AS c ON a. xtype = c. xtype LEFT OUTER JOIN
Sys. syscomments AS e ON a. cdefault = e. id LEFT OUTER JOIN
Sys. extended_properties AS p ON a. id = p. major_id AND a. colid = p. minor_id
WHERE (B. name = 'keyfactory ') AND (c. status <> '1 ')
-- B. name = 'keyfactory ', 'keyfactory' the data table you want to query.