如何查询数据库中所有表格,或者查询是否存在某个表格-mysql和oracle

这个问题,在之前就有写过,但是想找到语句还是记不得,这里主要提及我自己有用到的数据库mysql和oracle

1、mysql

  这个是自己安装的,所有配置都是默认配置没有改变,所以保存表名的表还是information_schema.tables,语句如下:

--获取数据库中所有用户名,表名
select table_schema 用户名,table_name 表名 from information_schema.tables
--获取'test'用户下所有表
select table_schema 用户名,table_name 表名 
from information_schema.tables
where table_schema='test'
--判断'test'用户下是否有'user'表
select * 
from information_schema.tables
where table_schema='test'
  and table_name='user' 
--在mysql里面表名、用户名可以不区分大小写,譬如下面语句也可以查询出结果
select * 
from information_schema.tables
where table_schema='TEST'
  and table_name='uSer'

2、Oracle

  这个不是我的数据库,而oralce中保存表名的表在网上也是众说纷纭,我最终找到的表是all_tables,而且它保存的表名作为字符串是区分大小写的

--取某个表
select * from all_tables WHERE upper(OWNER) LIKE '用户名大写' AND upper(TABLE_NAME) LIKE '表名大写'
--取库中所有表
select * from all_tables
select * from all_tables@想要的远程库

  

猜你喜欢

转载自www.cnblogs.com/liwxmyself/p/12066262.html