Check all SQL Server database dictionaries in three SQL views

Source: Internet
Author: User
Tags scalar

1. SQL Server 2000 database Dictionary (table structure. SQL)

Select top 100 PERCENT -- a. id,

Case when a. colorder = 1 THEN d. name ELSE ''end as table name,
Case when a. colorder = 1 THEN isnull (f. value, '') ELSE'' end as table description,
A. colorder as field No., a. name AS field name, case when columnproperty (a. id,
A. name, 'isidentity ') = 1 then' √ 'else' end as id,
CASE WHEN EXISTS
(SELECT 1
FROM dbo. sysindexes si INNER JOIN
Dbo. sysindexkeys sik ON si. id = sik. id AND si. indid = sik. indid INNER JOIN
Dbo. syscolumns SC ON SC. id = sik. id AND SC. colid = sik. colid INNER JOIN
Dbo. sysobjects so ON so. name = si. name AND so. xtype = 'pk'
WHERE SC. id = a. id AND SC. colid = a. colid) then' √ 'else' END AS primary key,
B. name AS type, a. length AS length, COLUMNPROPERTY (a. id, a. name, 'precision ')
AS precision, ISNULL (COLUMNPROPERTY (a. id, a. name, 'Scale'), 0) AS decimal places,
Case when a. isnullable = 1 THEN '√ 'else' end as allow null, ISNULL (e. text ,'')
AS default value, ISNULL (g. [value], '') AS field description, d. crdate AS creation time,
Case when a. colorder = 1 THEN d. refdate else null end as change time

FROM dbo. syscolumns a LEFT OUTER JOIN
Dbo. policypes B ON a. xtype = B. xusertype INNER JOIN
Dbo. sysobjects d ON a. id = d. id AND d. xtype = 'U' AND
D. status> = 0 LEFT OUTER JOIN
Dbo. syscomments e ON a. cdefault = e. id LEFT OUTER JOIN
Dbo. sysproperties g ON a. id = g. id AND a. colid = g. smallid AND
G. name = 'Ms _ description' LEFT OUTER JOIN
Dbo. sysproperties f ON d. id = f. id AND f. smallid = 0 AND
F. name = 'Ms _ description'
Order by d. name, a. colorder

 

2. SQL Server 2005 database Dictionary (table structure. SQL)

Select top 100 PERCENT -- a. id,
Case when a. colorder = 1 THEN d. name ELSE ''end as table name,
Case when a. colorder = 1 THEN isnull (f. value, '') ELSE'' end as table description,
A. colorder as field No., a. name AS field name, case when columnproperty (a. id,
A. name, 'isidentity ') = 1 then' √ 'else' end as id,
CASE WHEN EXISTS
(SELECT 1
FROM dbo. sysindexes si INNER JOIN
Dbo. sysindexkeys sik ON si. id = sik. id AND si. indid = sik. indid INNER JOIN
Dbo. syscolumns SC ON SC. id = sik. id AND SC. colid = sik. colid INNER JOIN
Dbo. sysobjects so ON so. name = si. name AND so. xtype = 'pk'
WHERE SC. id = a. id AND SC. colid = a. colid) then' √ 'else' END AS primary key,
B. name AS type, a. length AS length, COLUMNPROPERTY (a. id, a. name, 'precision ')
AS precision, ISNULL (COLUMNPROPERTY (a. id, a. name, 'Scale'), 0) AS decimal places,
Case when a. isnullable = 1 THEN '√ 'else' end as allow null, ISNULL (e. text ,'')
AS default value, ISNULL (g. [value], '') AS field description, d. crdate AS creation time,
Case when a. colorder = 1 THEN d. refdate else null end as change time
FROM dbo. syscolumns a LEFT OUTER JOIN
Dbo. policypes B ON a. xtype = B. xusertype INNER JOIN
Dbo. sysobjects d ON a. id = d. id AND d. xtype = 'U' AND
D. status> = 0 LEFT OUTER JOIN
Dbo. syscomments e ON a. cdefault = e. id LEFT OUTER JOIN
Dbo. sysproperties g ON a. id = g. id AND a. colid = g. smallid AND
G. name = 'Ms _ description' LEFT OUTER JOIN
Dbo. sysproperties f ON d. id = f. id AND f. smallid = 0 AND
F. name = 'Ms _ description'
Order by d. name, a. colorder

 

SQL Server database Dictionary (index. SQL)

Select top 100 PERCENT -- a. id,
Case when B. keyno = 1 THEN c. name ELSE ''END AS table name,
Case when B. keyno = 1 THEN a. name ELSE ''END AS index name, d. name AS column name,
B. keyno AS index order, CASE indexkey_property (c. id, B. indid, B. keyno, 'isdesending ')
WHEN 1 THEN 'descending order 'when 0 then' Ascending Order 'end AS sorting, case when p. id IS NULL
THEN ''else' √ 'end AS primary key, case indexproperty (c. id, a. name, 'isclustered ')
WHEN 1 THEN '√ 'when 0 then'' end as aggregation, case indexproperty (c. id,

A. name, 'isunique') WHEN 1 then' √ 'when 0 then'' end as unique,
Case when e. id is null then ''else' √ 'end AS unique constraint,
A. OrigFillFactor AS fill factor, c. crdate AS creation time, c. refdate AS change time
FROM dbo. sysindexes a INNER JOIN
Dbo. sysindexkeys B ON a. id = B. id AND a. indid = B. indid INNER JOIN
Dbo. syscolumns d ON B. id = d. id AND B. colid = d. colid INNER JOIN
Dbo. sysobjects c ON a. id = c. id AND c. xtype = 'U' LEFT OUTER JOIN
Dbo. sysobjects e ON e. name = a. name AND e. xtype = 'uq' LEFT OUTER JOIN
Dbo. sysobjects p ON p. name = a. name AND p. xtype = 'pk'
WHERE (OBJECTPROPERTY (a. id, N 'isusertable') = 1) AND (OBJECTPROPERTY (a. id,
N 'ismsshipped ') = 0) AND (INDEXPROPERTY (a. id, a. name, 'isautostatistics') = 0)
Order by c. name, a. name, B. keyno

 

SQL Server database Dictionary (primary key. Foreign key. constraint. View. function. Stored Procedure. Trigger. SQL)

SELECT DISTINCT
TOP 100 PERCENT o. xtype,
CASE o. xtype WHEN 'X' extended stored procedure 'when' tr'then' trigger 'when' pK' THEN
The 'when' f'then' foreign key 'when 'C' constraint 'when' V 'then' view 'when' FN'
Then' function-scalar 'when' IF 'then' function-nested 'when' TF 'then' function-Table value 'else' Stored Procedure'
End as type, o. name AS object name, o. crdate AS creation time, o. refdate AS change time,
C. text AS statement
FROM dbo. sysobjects o LEFT OUTER JOIN
Dbo. syscomments c ON o. id = c. id
WHERE (o. xtype IN ('x', 'tr', 'C', 'V', 'F', 'if', 'tf', 'fn, 'P ', 'pk') AND
(OBJECTPROPERTY (o. id, n' IsMSShipped ') = 0)
Order by case o. xtype WHEN 'X' then' extended stored procedure 'when' TR 'then' trigger 'when
'Pk 'then' primary key 'when' f'then' foreign key 'when'c' then' constraint 'when' v'then' view'
WHEN 'fn 'then' function-scalar 'when' IF 'then' function-nested 'when' TF 'then' function-Table value'
ELSE 'stored process' END DESC

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.