ifexists(select*fromdbo.sysobjectswhereid=object_id(N'[dbo].[Test]')andOBJECTPROPERTY(id,N'IsProcedure')=1)
dropprocedure[dbo].[Test]
GO
ifexists(select*fromdbo.sysobjectswhereid=object_id(N'[dbo].[testtable]')andOBJECTPROPERTY(id,N'IsUserTable')=1)
droptable[dbo].[testtable]
GO
CREATETABLE[dbo].[testtable](
[testid][int]NULL,
[counts][int]NULL
)ON[PRIMARY]
GO
insertintotesttable(testid,counts)values(1,0)
GO
SETQUOTED_IDENTIFIERON
GO
SETANSI_NULLSON
GO
CREATEProceduredbo.Test
as
declare@countint
begintranTEST
select@count=countsfromtesttablewheretestid=1
updatetesttablesetcounts=@count+1
if(@@error>0)begin
rollbacktranTEST
endelsebegin
committranTEST
end
GO
SETQUOTED_IDENTIFIEROFF
GO
SETANSI_NULLSON
GO