查看mysql數據庫是否存在某張表及某張表是否存在某個字段


1、通過information_schema查詢數據庫是否存在某張表

select t.table_name from information_schema.TABLES t where t.TABLE_SCHEMA ='".$database."' and t.TABLE_NAME ='".$table."';
$database:查詢的數據庫
$table :查詢表格

返回:若存在則返回表名,不存在返回為空

 2、判斷表中一個字段是否存在

select count(*) from information_schema.columns where table_name = '表名' and column_name = '字段名'

select count(*) from information_schema.columns where table_name = 't_iov_vehicle_owner_info' and column_name = 'id'

 


免責聲明!

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



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