Given that SQL Azure Federations does not support the IDENTITY or SEQUENCE property, what would be an efficient way to generate sequential numbers when inserting records?
For example, for a table with these columns:
CREATE TABLE [dbo].[Orders] ( [TenantId] [uniqueidentifier] NOT NULL, [OrderId] [uniqueidentifier] NOT NULL, [OrderNumber] [int] NOT NULL CONSTRAINT [PK_Orders] PRIMARY KEY CLUSTERED ( [TenantId] ASC, [OrderId] ASC ) ) FEDERATED ON ([FederationKey] = [TenantId])
for each order inserted for this tenant, the OrderId should be increased. For example, for tent A OrderId will be 1, 2, 3 ... and for tenant B OrderId will also be 1, 2, 3 ... in an independent sequence. Ideally, there should be no spaces.
TenantId and OrderId are components of the primary key. Their values ββare set by the application, and they are not related to the problem of generating sequences; only OrderId has a serial number with a business value. In addition, TenantId is a federation distribution key.
This MSDN blog article describes in Option 1 an approach to having a table containing sequences, and using a stored procedure in a separate transaction to increase the sequence. Each tenant must have an entry in this table containing the last used sequence value.
Will this be the best approach to scalability, competition, resource blocking? Any other useful tricks given the limitations of SQL Azure Federations?
source share