存储过程中事务书写基本格式 sample 1


CREATE PROCEDURE sp_AddSpecorDoc(
  @DocID  int,
 @Specid  int
 
)AS
begin tran
 select * from cms_spec_docs  where docid=@docid  and specid=@specid
if @@rowcount=0
 insert into cms_spec_docs (docid,specid)
  values (@docid,@specid)
if @@error<>0
begin
 rollback
 return(1)
end
else
begin
 commit
 return(0)
end


GO

你可能感兴趣的:(sample)