日期:2014-05-16  浏览次数:20400 次

几种数据库的SQL判断表是否存在

?Oracle:

?

?


declare
var_exists int;

begin
?select count(1) into var_exists from user_all_tables where table_name = upper('table_01');
?if (var_exists = 0) then
??execute immediate('create table table_01? (
???id?????????????? NUMBER(10)????????????????????? not null,
???name???????????? VARCHAR2(100)?????????????????? not null,
???constraint table_01_11735761881 primary key (id)
??)');
?end if;
end ;


/
commit;

?

?

Sybase:

?

if? not exists(select 1 from sysobjects where id = object_id('table_01) )
?
exec("create table table_01(
??? id??????????? numeric(10)?????????? not null,??????????????? --??
??? name????????? varchar(100)????????? not null,??????????????? --??
????primary key (id)????????????????????????
)")
go