常用資料庫查詢判斷表格和欄位是否存在的SQL(如果結果為1表示存在,為0表示不存在)
1、MSSQL Server
表:
SELECT COUNT(*) FROM dbo.sysobjects WHERE name= 'table_name';
欄位:
SELECT COUNT(*) FROM syscolumns WHERE id=object_id(‘table_name’) AND name= 'column_name';
表:
SELECT COUNT(*) FROM information_schema.tables WHERE table_name ='table_name';
欄位:
SELECT COUNT(*) FROM information_schema.columns WHERE table_name ='table_name' AND column_name ='column_name';
3、Oracle
表:
SELECT count(*) FROM USER_OBJECTS WHERE OBJECT_NAME = 'table_name';
rr
SELECT COUNT(*) FROM USER_TAB_COLUMNS WHERE TABLE_NAME ='table_name' AND column_name ='column_name';