当前位置: 代码迷 >> 综合 >> SQL Cookbook 系列 - 元数据查询
  详细解决方案

SQL Cookbook 系列 - 元数据查询

热度:12   发布时间:2024-01-15 16:11:55.0
  1. 列出模式中的表
  2. 列出表的列
  3. 列出表的索引列
  4. 列出表约束
  5. 列出没有相应索引的外键
  6. 使用SQL来生成SQL
  7. 在oracle中描述数据字典视图

元数据在数据库中是用来描述其他数据库对象的数据,例如描述表,约束,索引等。
这个按照我的理解来看,元数据是数据库管理数据库对象的记录。

1.列出模式中的表
查看在给出模式中所有已创建的表的清单:
db2 : select tabname from syscat.tables where tabschema='SNEAGOL';
oracle : select table_name from all_tables where owner='SMEAGOL';
postgreSQL,mysql,sqlserver: select table_name from information_schema.tables where table_schema='SMEAGOL';
Note: schema的值是当前数据库的schema

2.列出表的列
列出表的各列、数据类型、表中的位置
db2: select colname,typename,colno from syscat.columns where tabname='emp' and tabschema='GOL';
oracle: select column_name,data_type,column_id from all_tab_columns where owner='GOL' and table_name='EMP';
postgreSQL,mysql,sqlserver: s