首页 > 关于生成id的问题

关于生成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 = @serialnameupdate SystemVariable set SV_nSerial = @max+1 where SV_strName = @serialname and SV_nSerial = @max

转载于:https://www.cnblogs.com/HeroBeast/archive/2011/12/09/2282280.html

更多相关: