表明 | 表最大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 ends
方法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