Use three SQL views to find all database dictionaries _ MySQL

Source: Internet
Author: User
The SQL code in this article can be simply executed in the enterprise manager and query analyzer to identify all the data dictionaries of SQL Server 2000 and SQL Server 2005. (Note: database dictionaries include table structures (SQL Server 2000 and SQL Server 2005), indexes, primary keys, foreign keys, constraints, views, functions, stored procedures, and triggers .)

SQL Server 2000 database dictionary-table structure. SQL

Select top 100 PERCENT --. id, case when. colorder = 1 THEN d. name ELSE ''end AS table name, case when. colorder = 1 THEN isnull (f. value, '') else' end as table description,. colorder AS field number,. name AS field name, case when columnproperty (. id,. name, 'isidentity ') = 1 then' √ 'else' end as id, case when exists (SELECT 1 FROM dbo. sysindexes si INNER JOINdbo. sysindexkeys sik ON si. id = sik. id AND si. indid = sik. indid INNER JOINdbo. syscolumns SC ON SC. id = sik. id AND SC. colid = sik. colid INNER JOINdbo. sysobjects so ON so. name = si. name AND so. xtype = 'PK' WHERE SC. id =. id AND SC. colid =. colid) THEN '√ 'else' 'end AS primary key, B. name AS type,. length AS length, COLUMNPROPERTY (. id,. name, 'Precision ') as precision, ISNULL (COLUMNPROPERTY (. id,. name, 'scale'), 0) AS decimal places, case when. isnullable = 1 then' √ 'else' end as can be null, ISNULL (e. text, '') AS default value, ISNULL (g. [value], '') AS field description, d. crdate AS creation time, case when. colorder = 1 THEN d. refdate else null end as change time FROM dbo. syscolumns a left outer JOINdbo. policypes B ON. xtype = B. xusertype INNER JOINdbo. sysobjects d ON. id = d. id AND d. xtype = 'u' AND d. status> = 0 left outer JOINdbo. syscomments e ON. cdefault = e. id left outer JOINdbo. sysproperties g ON. id = g. id AND. colid = g. smallid AND g. name = 'Ms _ description' left outer JOINdbo. sysproperties f ON d. id = f. id AND f. smallid = 0 AND f. name = 'Ms _ description' order by d. name,. colorder

SQL Server 2005 database dictionary-table structure. SQL

Select top 100 PERCENT --. id, case when. colorder = 1 THEN d. name ELSE ''end AS table name, case when. colorder = 1 THEN isnull (f. value, '') else' end as table description,. colorder AS field number,. name AS field name, case when columnproperty (. id,. name, 'isidentity ') = 1 then' √ 'else' end as id, case when exists (SELECT 1 FROM dbo. sysindexes si INNER JOINdbo. sysindexkeys sik ON si. id = sik. id AND si. indid = sik. indid INNER JOINdbo. syscolumns SC ON SC. id = sik. id AND SC. colid = sik. colid INNER JOINdbo. sysobjects so ON so. name = si. name AND so. xtype = 'PK' WHERE SC. id =. id AND SC. colid =. colid) THEN '√ 'else' 'end AS primary key, B. name AS type,. length AS length, COLUMNPROPERTY (. id,. name, 'Precision ') as precision, ISNULL (COLUMNPROPERTY (. id,. name, 'scale'), 0) AS decimal places, case when. isnullable = 1 then' √ 'else' end as can be null, ISNULL (e. text, '') AS default value, ISNULL (g. [value], '') AS field description, d. crdate AS creation time, case when. colorder = 1 THEN d. refdate else null end as change time FROM dbo. syscolumns a left outer JOINdbo. policypes B ON. xtype = B. xusertype INNER JOINdbo. sysobjects d ON. id = d. id AND d. xtype = 'u' AND d. status> = 0 left outer JOINdbo. syscomments e ON. cdefault = e. id left outer JOINdbo. sysproperties g ON. id = g. id AND. colid = g. smallid AND g. name = 'Ms _ description' left outer JOINdbo. sysproperties f ON d. id = f. id AND f. smallid = 0 AND f. name = 'Ms _ description' order by d. name,. colorder


SQL Server database dictionary-index. SQL

Select top 100 PERCENT --. id, case when B. keyno = 1 THEN c. name ELSE ''end AS table name, case when B. keyno = 1 THEN. 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, 'isscending') WHEN 1 then' in descending order 'When 0 then' in ascending order 'end AS sorting, case when p. id is null then ''else' √ 'end AS primary key, case indexproperty (c. id,. name, 'isclustered') WHEN 1 then' √ 'When 0 then'' end as aggregation, case indexproperty (c. id,. name, 'isunique') WHEN 1 then' √ 'When 0 then'' end as unique, case when e. id is null then ''else' √ 'end AS unique constraint,. origFillFactor AS fill factor, c. crdate AS creation time, c. refdate AS change time FROM dbo. sysindexes a INNER JOINdbo. sysindexkeys B ON. id = B. id AND. indid = B. indid INNER JOINdbo. syscolumns d ON B. id = d. id AND B. colid = d. colid INNER JOINdbo. sysobjects c ON. id = c. id AND c. xtype = 'U' left outer JOINdbo. sysobjects e ON e. name =. name AND e. xtype = 'uq' left outer JOINdbo. sysobjects p ON p. name =. name AND p. xtype = 'PK' WHERE (OBJECTPROPERTY (. id, N 'isusertable') = 1) AND (OBJECTPROPERTY (. id, n' IsMSShipped ') = 0) AND (INDEXPROPERTY (. id,. name, 'isautostatistics ') = 0) order by c. name,. 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' 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 procedure 'end AS type, o. name AS object name, o. crdate AS creation time, o. refdate AS change time, c. text AS declaration statement FROM dbo. sysobjects o left outer JOINdbo. syscomments c ON o. id = c. idWHERE (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' 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 procedure 'end DESC

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.