mysql 获取数据库名、表名、字段名、根据表结构创建新表

1、查询当前使用的数据库

select database();

 

2、获取当前数据库表

select * from information_schema.TABLES where TABLE_SCHEMA=(select database())

 

第二种方法,不能使用union all 等方式。

show full columns from table_name

 

3、获取表中字段

select * from information_schema.COLUMNS where table_name = 'table_name' and table_schema = (select database());

 

 4、使用一个表结构创建新表

 CREATE TABLE IF NOT EXISTS `table_name` like `new_table_name`

 

posted @ 2020-12-17 18:31  dcrenl  阅读(811)  评论(0编辑  收藏  举报