27,579
社区成员
发帖
与我相关
我的任务
分享
--创建测试表test
create table test(a int, b int)
go
create table test1(a int, b int)
go
--插入测试数据
insert into test
select 1, 2 union all
select 2, 2 union all
select 3, 2 union all
select 4, 2
go
insert into test1
select 1, 3 union all
select 2, 3 union all
select 3, 3 union all
select 4, 3
go
--创建测试存储过程
create proc sp_test
as
begin
set transaction isolation level repeatable read
begin tran
begin try
select *
from test
select *
from test1 --此表不存在,名称延迟解析
commit tran
end try
begin catch --catch是不能抛出名称延迟解析的错误以及编译错误
rollback tran
return (1)
end catch
return (0)
end
exec sp_test
update test
set b = 6
from test
IF OBJECT_ID('[表名]') IS NOT NULL
[存在时的代码]
ELSE
[不存在时的代码]