几大数据库常用语句

H2: 

-- 测试版本: 1.4.193
create table a_tb(id varchar(32));
drop table if exists a_tb;

MSSQL:

-- 测试版本: SQLServer 2008R2
create table a_tb(id varchar(32));
if object_id(N'dbo.a_tb', N'U') is not null 
	drop table dbo.a_tb;

MySQL:

-- 测试版本: 5.0.67
create table a_tb(id varchar(32));
drop table if exists a_tb;

Oracle:

-- 测试版本号: 11.2.0.1.0 - 64bit
-- 创建表
create table a_tb(id varchar(32));
-- 查询表及所属用户
select owner,table_name from all_tables where table_name=upper('a_tb'); -- EPN_BIZ,A_TB
-- 删除该用户下的表
declare table_exist int;
begin
    select count(*) into table_exist from all_tables 
    where owner=upper('epn_biz') and table_name=upper('a_tb');
    if table_exist = 1 then    
      execute immediate 'drop table epn_biz.a_tb';
    end if;
end;

参考文献: Oracle: If Table Exists

发布了64 篇原创文章 · 获赞 34 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/svygh123/article/details/103484017
今日推荐