1.判斷數據庫是否存在
select 1 from information_schema.schemata where schema_name='數據庫名';
指定數據庫名查詢是否存在,若存在則返回1,若不存在測返回空。
2.判斷表是否存在
select 1 from information_schema.tables where table_schema='數據庫名' and table_name ='表名';
指定表名查詢是否存在,若存在則返回1,若不存在測返回空。(需指定在哪個數據庫查詢,若不指定則在整個服務上查詢)
3.判斷列是否存在
select 1 from information_schema.columns where table_schema='數據庫名' and table_name='表名' and column_name ='列名';
指定列名查詢是否存在,若存在則返回1,若不存在測返回空。(需指定在哪個數據庫查詢,若不指定則在整個服務上查詢)