欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

简单实用:Oracle/Sqlserver/Sqlite 判断某张表是否存在的SQL语句

程序员文章站 2022-07-08 23:50:49
...
简单实用:Oracle/Sqlserver/Sqlite 判断某张表是否存在的SQL语句
1.Oracle

SELECT COUNT(*) as count
FROM all_tables
WHERE table_name= 'tablename'
不存在返回0

2.Sqlserver

SELECT COUNT(*)
FROM sys.objects
WHERE object_id = OBJECT_ID(N'tablename') AND type in (N'U')
不存在放回0

3.Sqlite

SELECT COUNT(*) as count
FROM sqlite_master
WHERE type='table' and name= 'tablename'
不存在放回0