表存在则删除,不存在则创建(一句sql实现)
通过一句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 ex
·
通过一句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。
更多推荐
已为社区贡献1条内容
所有评论(0)