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`

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM