I'm trying to make an even simpler function than the one described here to get the next value of an order number for a shopping cart.
- I don't care if there are gaps
- Only completed orders get an ID (i.e. I'm deliberately not using IDENTITY)
- Obviously there must not be duplicates
- I don't care about performance and locking. If we have so many new orders that I care about lockin then I'll have other problems first
I've found quite a few other similar questions, but not the exact solution i'm looking for.
What I have so far is this :
USE [ShoppingCart]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Sequence_CompletedOrderID]
([val] [int] NOT NULL
CONSTRAINT [DF_Sequence_CompletedOrderID_NextValue] DEFAULT ((520000))
) ON [PRIMARY]
then for the stored proc :
CREATE PROC dbo.GetNextCompletedOrderId
@nextval AS INT OUTPUT
AS
UPDATE dbo.sequence_completedorderid SET @nextval=val += 1;
GO
Like I said I'm trying to base it on the article I linked to above - so perhaps this just a clumsy way of doing it. My SQL isn't quite up to much for even simple things like this, and its past my bedtime. Thanks!