tsql-sequence

Insert using a Sequence as generator for a Primary Key value in Entity Framework

房东的猫 提交于 2019-12-10 18:24:48
问题 I have a sequence that looks like this: CREATE SEQUENCE dbo.NextWidgetId AS [bigint] START WITH 100 INCREMENT BY 2 NO CACHE GO And a table that looks like this: CREATE TABLE [dbo].[Widget_Sequenced] ( [WidgetId] [int] NOT NULL DEFAULT(NEXT VALUE FOR dbo.NextWidgetId), [WidgetCost] [money] NOT NULL, [WidgetName] [varchar](50) NOT NULL, [WidgetCode] [int] NOT NULL, [LastChangedBy] [int] NOT NULL, [RowVersionId] [timestamp] NOT NULL, CONSTRAINT [PK_Widget_Sequenced] PRIMARY KEY CLUSTERED (