欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SQL SERVER 里的错误处理(try catch)

程序员文章站 2022-11-21 10:54:40
begin try …… end try begin catch …… end catch。 另外,with 语句如果前面还有别的sql语句,应该在前面的sql语句结尾加上...
begin try
……
end try
begin catch
……
end catch。
另外,with 语句如果前面还有别的sql语句,应该在前面的sql语句结尾加上分号";"。比如在这个try catch里,就应该在前面加个";",如下:
begin try

with w as(
select f1,f2,f3
,row_number() over(order by id desc) as row
from [t1]
where code=@code
)
insert into [t2](
f1,f2,f3
select f1,f2,f3
from w where row>100;
end try
begin catch
end catch;