关于生成id的问题

表明 表最大id
   

 

方法1:

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[getserial] @serialname char(30) AS
begin
declare @serialno int
begin transaction
select @serialno = SV_nSerial from SystemVariable with(TABLOCKX HOLDLOCK) where SV_strName = @serialname
if @serialno is null
begin
commit
raiserror 50010 'SystemVariable lack record'
end
else
begin
update SystemVariable set SV_nSerial = @serialno+1 where SV_strName = @serialname
commit
select @serialno+1
end
end
s

方法2:

declare @max int
select @max = SV_nSerial from SystemVariable where SV_strName = @serialname

update SystemVariable set SV_nSerial = @max+1 where SV_strName = @serialname and SV_nSerial = @max
posted @ 2011-12-09 15:18  herobeast  阅读(255)  评论(0编辑  收藏  举报