加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

SQL语句查询所有数据库名和表名

(2016-10-08 14:03:36)
标签:

mysql

mssql

oracle

模糊查询

分类: 数据仓库
PS:本来主打的想利用模糊查询大量表中某字段内容的结果,奈何MSSQL存储过程未测试成功,暂标记下
有两个帖子看着不错,待通用优化
http://blog.csdn.net/zhang399401/article/details/51735550
http://bbs.csdn.net/topics/300235445
http://www.jb51.net/article/34706.htm

找到几个频率高点的语句,摘抄记录下

0x01MySQL中查询所有数据库名和表名

查询所有数据库
show databases;

查询指定数据库中所有表名
select table_name from information_schema.tables where table_schema='database_name' and table_type='base table';

查询指定表中的所有字段名
select column_name from information_schema.columns where table_schema='database_name' and table_name='table_name';

查询指定表中的所有字段名和字段类型
select column_name,data_type from information_schema.columns where table_schema='database_name' and table_name='table_name';

检索数据库中包含某几个字段的表
SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME IN ('staff_id');

检索表名称包含某些字符的表
SELECT * FROM information_schema.tables WHERE table_name LIKE '%mail%';


0x02SQLServer中查询所有数据库名和表名

查询所有数据库
select * from sysdatabases;

查询当前数据库中所有表名
select * from sysobjects where xtype='U';
xtype='U':表示所有用户表,xtype='S':表示所有系统表。
若模糊查询指定字符串的表名称可用:
select * from sysobjects where xtype='U' and name like '%user%';

查询指定表中的所有字段名
select name from syscolumns where id=Object_Id('table_name');

查询指定表中的所有字段名和字段类型
select sc.name,st.name from syscolumns sc,systypes st where sc.xtype=st.xtype and sc.id in(select id from sysobjects where xtype


0x03Oracle中查询所有数据库名和表名
查询所有数据库
由于Oralce没有库名,只有表空间,所以Oracle没有提供数据库名称查询支持,只提供了表空间名称查询。
select * from v$tablespace;  --查询表空间(需要一定权限)


查询当前数据库中所有表名
select * from user_tables;

查询指定表中的所有字段名
select column_name from user_tab_columns where table_name = 'table_name';

查询指定表中的所有字段名和字段类型
select column_name, data_type from user_tab_columns where table_name = 'table_name';




0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有