SQL SERVER 中的if exists
表:
if exists(SELECT * FROM SYSOBJECTS WHERE NAME='tab_1')
drop table tab_1
create table tab_1(t1 varchar(20));
储存过程:
if exists(SELECT * FROM SYSOBJECTS WHERE NAME='proc_name')
drop PROCEDURE proc_name;
GO --此处必须加GO
create PROCEDURE proc_name
表:
if exists(SELECT * FROM SYSOBJECTS WHERE NAME='tab_1')
drop table tab_1
create table tab_1(t1 varchar(20));
储存过程:
if exists(SELECT * FROM SYSOBJECTS WHERE NAME='proc_name')
drop PROCEDURE proc_name;
GO --此处必须加GO
create PROCEDURE proc_name
AS
BEGIN
END
ORACLE 中的 "if exists"
表:
declare
cou1 number;
begin
select count(*) into cou1 from user_tables where table_name='T_TEMP';
if cou1 <> 0 then
execute immediate 'drop table T_TEMP';
end if;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line(DBMS_UTILITY.format_error_stack);
DBMS_OUTPUT.put_line(DBMS_UTILITY.format_call_stack);
end;
/
create table T_TEMP (t1 varchar2(100));