通过一句sql实现:

1、表存在则删除;2、表不存在则创建;

 

mysql:

drop table if exists `test`;
create table if not exists `test` (`id` integer not null, `name` varchar(10), primary key(`id`));

 

sqlserver:

if exists (select count(*) from [sys].[schemas] S JOIN [sys].[tables] T ON S.schema_id = T.schema_id where S.name='ms-1')
drop table [ms-1];

if not EXISTS(select count(*) from [sys].[schemas] S JOIN [sys].[tables] T ON S.schema_id = T.schema_id where S.name='ms-1')
CREATE TABLE [ms-1] (
	[id] INTEGER not null,
	[name] VARCHAR(10),
	PRIMARY KEY([id]
);

 

 

oracle:

declare num number; 
begin
    select count(*) into num from all_tables where TABLE_NAME = 'tt-1' and OWNER='ODBC'; 
    if num=1 then 
        execute immediate 'drop table "tt-1"';
    end if;
end;

 

 

dameng:

同oracle。

 

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐