1 2

sql获取mysql所有数据库,表名

当面对可能存在的大数据,不能把所有数据放在一张表里,否则会影响到查询效率,那么我们需要对数据库进行分表分区,例如一天一张表,当插入数据时,判断表是否存在,不存在则创建新表,并进行数据插入。

如果我们需要在程序中通过sql语句查询来获得存在的数据库,以及某个数据库的所有表名,可以这样写:

#查询所有的数据库名称
SELECT SCHEMA_NAME AS `Database` FROM INFORMATION_SCHEMA.SCHEMATA;

#查询指定数据库下的所有表名(例如sw_wbdlp_basic_db_v1数据库下的所有表名)

select table_name from information_schema.TABLES where TABLE_SCHEMA='sw_wbdlp_basic_db_v1' and TABLE_TYPE = 'base table';

执行结果:

获取数据库名:

 

 表名:

 不同数据库备份复制表的sql

Sql server :
select * into table_new from table_old ; 复制结构和数据
select * into table_new from table_old where 1=2;只复制结构
Oracle:
create table table_new as select * from table_old;复制结构和数据
create table table_new as select * from table_old where 1=0;只复制结构
DB2:
--复制表结构
create table table_name_new as (select * from table_name_old) definition only;

 

posted @ 2020-07-15 17:59  大海的泡沫  阅读(4411)  评论(0编辑  收藏  举报
1 2