if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Test]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Test]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[testtable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[testtable]
GO
CREATE TABLE [dbo].[testtable] (
[testid] [int] NULL ,
[counts] [int] NULL
) ON [PRIMARY]
GO
insert into testtable (testid,counts) values (1,0)
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Procedure dbo.Test
as
declare @count int
begin tran TEST
select @count=countsfrom testtable where testid=1
update testtable setcounts=@count+1
if (@@error >0) begin
rollback tran TEST
end else begin
commit tran TEST
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO