关于生成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 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
轉(zhuǎn)載于:https://www.cnblogs.com/HeroBeast/archive/2011/12/09/2282280.html
總結(jié)
- 上一篇: 是你给我的心是什么歌呢?
- 下一篇: 阿拉蕾参加过什么综艺节目?