I have a table and I am trying to insert values in it. I want to prevent gaps in the primary key column. For primary column I have tried using Identity / sequence objects. I know that this is potential drawback of using Identity or sequence object; but is there any work around? I am open to using some other technique to prevent gaps.
Here is the table structure and sample code:
CREATE SEQUENCE Service_Ticket_Seq
AS INTEGER
START WITH 1
INCREMENT BY 1
MINVALUE 1
MAXVALUE 100
CYCLE;
CREATE TABLE Meats
(ticket_seq INTEGER NOT NULL primary key default (NEXT VALUE FOR Service_Ticket_Seq) ,
meat_type VARCHAR(15) NOT NULL)
ROW_NUMBER() over (ORDER BY ID)to sequence its results without gaps. – Pieter Geerkens Sep 28 '14 at 14:57Microsoft SQL Server Management Studio 11.0.3128.0 Microsoft Analysis Services Client Tools 11.0.3128.0 Microsoft Data Access Components (MDAC) 6.2.9200.16384 Microsoft MSXML 3.0 6.0 Microsoft Internet Explorer 9.10.9200.16843 Microsoft .NET Framework 4.0.30319.18449 Operating System 6.2.9200
– user2438237 Sep 28 '14 at 17:43Microsoft SQL Server 2012 (SP1) - 11.0.3000.0 (X64) Oct 19 2012 13:38:57 Copyright (c) Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 6.2 (Build 9200: )
– user2438237 Sep 30 '14 at 11:39