use tempdb go --豐蠍一誤 create table dbo.Sequence(seq int) insert dbo.Sequence values(1) go create proc dbo.usp_Sequence @option tinyint --1:currval, 2:nextval, , @increment int = 1 as declare @seq int; if @option = 2 begin update dbo.Sequence set @seq = seq = seq + @increment; end else set @seq = (select top 1 seq from dbo.Sequence); return @seq; go --: 螳 declare @seq int exec @seq = dbo.usp_Sequence 1 select @seq --: れ螳 declare @seq int exec @seq = dbo.usp_Sequence 2 select @seq