SQL statement used to obtain the MSSQL Data Dictionary

Source: Internet
Author: User

Copy codeThe Code is as follows:
Create view dbo. vw_db_dictionary
AS
Select top 100 PERCENT dbo. sysobjects. name AS table_name,
Dbo. sysproperties. [value] AS table_desc, dbo. syscolumns. name AS field,
Properties. [value] AS field_desc, dbo. policypes. name AS field_type,
Dbo. syscolumns. length AS field_size,
ISNULL (COLUMNPROPERTY (dbo. syscolumns. id, dbo. syscolumns. name, 'Scale'), 0)
AS field_precision, dbo. syscolumns. isnullable AS nullable,
Case when 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 is_identity, 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 is_key
FROM dbo. syscolumns INNER JOIN
Dbo. sysobjects ON dbo. sysobjects. id = dbo. syscolumns. id INNER JOIN
Dbo. policypes ON dbo. syscolumns. xtype = dbo. policypes. xtype LEFT OUTER JOIN
Dbo. sysproperties properties ON dbo. syscolumns. id = properties. id AND
Dbo. syscolumns. colid = properties. smallid LEFT OUTER JOIN
Dbo. sysproperties ON dbo. sysobjects. id = dbo. sysproperties. id AND
Dbo. sysproperties. smallid = 0 LEFT OUTER JOIN
Dbo. syscomments ON dbo. syscolumns. cdefault = dbo. syscomments. id
WHERE (dbo. sysobjects. xtype = 'U ')
Order by dbo. sysobjects. name

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.