SQL 判斷表、字段是否存在的方法(MSSQL Server、Oracle、MySQL、PostgreSql、SQLite)


SQL 判斷表、字段是否存在的方法(MSSQL Server、Oracle、MySQL、PostgreSql、SQLite)

 1、MSSQL Server

select  count(*)  from  dbo.sysobjects where name=  '表名';  --  表
select  count(*)  from syscolumns where id=object_id(‘表名’)  and name=  '字段名';  --  字段 

2、Oracle

select count(*) from user_objects where  object_name =  '表名';  --  表
select count(*) from user_tab_columns where table_name = '表名' and column_name = '字段名';   --  字段

3、MySQL

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

4、PostgreSql

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

5、SQLite

select * from sqlite_master where name='表名' 
select * from sqlite_master where name='表名' and sql like '%字段名%';

6、其他往期擴展  鏈接

 

 

 

創建時間:2021.11.09  更新時間:2022.06.06

 


免責聲明!

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



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