换成表名和字段名,如果能查询出来结果,就说明响应表存在相应字段,如果没有就不存在。
常用数据库查询判断表和字段是否存在
数据库postgresql表是否存在字段是否存在oracle
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';
2、My SQL
表: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';
字段:SELECT COUNT(*) FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'table_name' and column_name = 'column_name';
4、PostgreSql
表:select count(*) from information_schema.tables WHERE table_schema='table_schema' and table_name ='table_name';
字段:select count(*) from information_schema.columns WHERE table_schema='table_schema'
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)