第五章 元数据查询 查询数据库本身信息 表结构 索引等

5.1 查询test库下的所有表信息

MYSQL

SELECT * from information_schema.`TABLES` WHERE TABLE_SCHEMA = 'test';

ORACLE

select table_name from all_tables where owner = 'test';

5.2 查询表中列的信息

MYSQL

SELECT * from information_schema.`COLUMNS` WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'student';

ORACLE

select * from all_tab_columns where owner = 'test' and table_name = 'student';

5.3 列出表的索引

MYSQL

show index from emp;

ORACLE

select table_name,index_name,column_name,column_position from sys.all_ind_columns where table_name = 'emp' and table_owner = 'test';

5.4 列出表约束

ORACLE

select a.table_name,a.constraint_name,b.coulumn_name,a.constraint_type from all_constraints a,all_cons_columns b where a.table_name = 'EMP' and a.owner = 'test' and a.table_name = b.table_name and a. owner = b.owner and a.constraint_name = b.constraint_name;

MYSQL

select a.table_name,a.constraint_name,b.coulumn_name,a.constraint_type from information_schema.table_constraints a,information_schema.key_column_usage b where a.table_name = 'EMP' and a.table_schema= 'test' and a.table_name = b.table_name and a. table_schema = b.table_schema and a.constraint_name = b.constraint_name;

5.5 显示表结构

desc user;

SQL.Cookbook 读书笔记5 元数据查询的更多相关文章

  1. SQL.Cookbook 读书笔记2 查询结果排序

    第二章 查询结果排序 2.1 按查询字段排序 order by sal asc; desc;-- 3表示sal 2.2 按子串查询 );--按job的最后两个字符排序 2.3 对字符数字混合排序 cr ...

  2. 《SQL CookBook 》笔记-第二章-查询结果排序

    目录 第二章 查询结果排序 2.1 以指定顺序返回查询结果 2.2 依据子串排序 2.3 排序时对 Null 值的处理 2.4 依据条件逻辑动态调整排序项 第二章 shanzm 第二章 查询结果排序 ...

  3. SQL.Cookbook 读书笔记3 操作多个表

    第三章 操作多个表 表连接的内连接和外连接 A表 B表id name id name 1 a 1 b 2 b 3 c4 c内连接就是左表和右表相同的数据,查询结果只有相等的数据:select * fr ...

  4. SQL.Cookbook 读书笔记4 插入更新和删除

    第四章 插入更新和删除 4.1 插入数据 ,'PROGRA','NEW YOURK'); 4.2 从一个表向另一个表中复制 insert into dept_east(deptno,dname,loc ...

  5. Linux Shell Scripting Cookbook 读书笔记 1

    本系列文章为<Linux Shell Scripting Cookbook>的读书笔记,只记录了我觉得工作中有用,而我还不是很熟练的命令 书是很好的书,有许多命令由于我比较熟悉,可能就没有 ...

  6. 《SQL CookBook 》笔记-第三章-多表查询

    目录 3.1 叠加两个行集 3.2 合并相关行 3.3 查找两个表中相同的行 3.4 查找只存在于一个表中的数据 3.5 从一个表检索与另一个表不相关的行 3.6 新增连接查询而不影响其他连接查询 3 ...

  7. 《SQL CookBook 》笔记-第三章-多表查询-连接查询

    目录 1 内连接(inner join) 1.1 隐式的内连接 1.2 显式的内连接 2 外连接(outer join) 2.1 左连接(left outer join) 2.2 右连接(right ...

  8. 《SQL Server 2012 T-SQL基础》读书笔记 - 4.子查询

    Chapter 4 Subqueries 子查询分为:独立子查询(Self-Contained Subqueries)和相关子查询(Correlated Subqueries),独立子查询可以单独拿出 ...

  9. 《SQL Server 2012 T-SQL基础》读书笔记 - 7.进阶查询

    Chapter 7 Beyond the Fundamentals of Querying window function是什么呢?就是你SELECT出来一个结果集,然后对于每一行,你都想给它对应一个 ...

随机推荐

  1. jquery ajax/post 请求 案例

    @RequestMapping("/hello")    @ResponseBody    public Hello getJson(HttpServletRequest requ ...

  2. [Javascript] Use a Pure RNG with the State ADT to Select an Element from State

    The resultant in a State ADT instance can be used as a means of communication between different stat ...

  3. 【原】使用StarUML画用例图

    在写一份升级方案的时候,发现文字描述半天,好多句子,依然不容易被人看明白,使用visio画了个流程图,后来觉得画个时序图是最清晰得了. 于是在找了一个工具: startUML,当然,做时序图,建模之类 ...

  4. @Autowired与@Resource的使用方法和差别

    一.@Autowired: 1.Spring 2.5 引入了 @Autowired 凝视,它能够对类成员变量.方法及构造函数进行标注,完毕自己主动装配的工作. 通过 @Autowired的使用来消除 ...

  5. 【DB2】DB2中rank(),dense_rank(),row_number()的用法

    1.准备测试数据 DROP TABLE oliver_1; ),SUB_NO ),SCORE int); ,,); ,,); ,,); ,,); ,,); ,,); 2.详解rank(),dense_ ...

  6. 通过Spring使用远程访问和web服务

    http://docs.huihoo.com/spring/zh-cn/remoting.html     Spring2 提供的remote包学习笔记

  7. NSDate相差8小时

     NSDate *date = [NSDate date]; NSTimeZone *zone = [NSTimeZone systemTimeZone]; NSInteger interval = ...

  8. HTML5事件-pageshow 和 pagehide

    <!doctype html> <html> <head> <title>html5事件</title> <meta charset= ...

  9. CentOS系统时间与网络同步

    新装的CentOS系统server可能设置了错误的,须要调整时区并调整时间.例如以下是CentOS系统使用NTP来从一个时间server同步: 第一步: 把当前时区调整为上海就是+8区,想改其它时区也 ...

  10. 因DataTable的字段值为DBNull引发的异常

    1 问题重现 (1)新建项目DBNullExp.项目属性为"控制台应用程序": (2)在项目下新建数据集Schools(数据集文件的后缀名为.xsd): watermark/2/t ...