数据库元数据数据字典查询_3_列出给定表的基本信息
生活随笔
收集整理的這篇文章主要介紹了
数据库元数据数据字典查询_3_列出给定表的基本信息
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? ? ? ? ? ? ? ? ? ? ? ? ? 列出給定表的基本信息
需求描述
需求:查詢出給定的表dept,emp,bonus,salgrade里的表名,字段名、字段類型、字段注釋、表注釋信息。
解決方法:通過各個數據庫里提供的與數據庫相關的數據字典進行查詢。
注: 數據庫數據集SQL腳本詳見如下鏈接地址
員工表結構和數據初始化SQL腳本
SQL代碼
-- Oracle: SELECT B.TABLE_NAME,B.COLUMN_NAME,B.DATA_TYPE,A.COMMENTS AS Table_Comm ,C.COMMENTS AS Column_Comm from user_tab_comments A JOIN user_tab_columns BON A.TABLE_NAME = B.TABLE_NAME JOIN user_col_comments C ON B.TABLE_NAME = C.TABLE_NAME AND B.COLUMN_NAME = C.COLUMN_NAME WHERE A.TABLE_NAME IN('DEPT','EMP','BONUS','SALGRADE')-- Mysql: SELECT A.TABLE_NAME,A.COLUMN_NAME,A.DATA_TYPE,B.TABLE_COMMENT AS Table_Comm,A.COLUMN_COMMENT AS Column_Comm FROM INFORMATION_SCHEMA.COLUMNS A JOIN INFORMATION_SCHEMA.TABLES BON A.TABLE_NAME = B.TABLE_NAME WHERE A.TABLE_SCHEMA='SHENL' AND A.TABLE_NAME IN('DEPT','EMP','BONUS','SALGRADE')-- Sql Server:USE Shenl; GO SELECTA.name AS table_name,B.name AS column_name,C.name AS data_type,D.value AS column_comm FROM sys.tables A INNER JOIN ( SELECT B.object_id,NULL AS name ,NULL AS user_type_id,0 as column_id FROM sys.tables A INNER JOIN sys.columns B ON B.object_id = A.object_id WHERE A.name IN ('dept','emp','bonus','salgrade') AND column_id = 1UNION SELECT object_id,name,user_type_id,column_id FROM sys.columns )B ON B.object_id = A.object_id LEFT JOIN sys.systypes C ON B.user_type_id = C.xtype INNER JOIN sys.extended_properties D ON D.major_id = B.object_id AND D.minor_id = B.column_id WHERE A.name IN ('dept','emp','bonus','salgrade') ORDER BY A.name-- 或: USE Shenl; GO SELECT table_name,column_name,data_type,column_comm,F.value as table_comm FROM ( SELECT A.object_id AS Object_id, A.name AS table_name,B.name AS column_name,C.name AS data_type,D.value AS column_comm FROM sys.tables A INNER JOIN sys.columns B ON B.object_id = A.object_id LEFT JOIN sys.systypes C ON B.user_type_id = C.xtype INNER JOIN sys.extended_properties D ON D.major_id = B.object_id AND D.minor_id = B.column_id WHERE A.name IN ('dept','emp','bonus','salgrade') )E JOIN ( SELECT major_id,value FROM sys.extended_properties A JOIN sys.tables B ON A.major_id = B.object_id AND B.name IN ('dept','emp','bonus','salgrade') AND A.minor_id = 0 )F ON E.object_id = F.major_id執行結果
總結
以上是生活随笔為你收集整理的数据库元数据数据字典查询_3_列出给定表的基本信息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 原切牛排哪个品牌好 推荐几个口碑不错的品
- 下一篇: 股票被打上“退”的烙印,会进入退市整理期