参数table_name和column_name的值均为大写:
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' and table_name ='table_name' and column_name='column_name';
本文提供了在MSSQLServer、MySQL、Oracle及PostgreSQL中查询表及字段存在的SQL语句,适用于不同数据库系统的表和字段检查。
1710

被折叠的 条评论
为什么被折叠?



