Reputation: 1
I put auto increment to my primary key and basically I want it to increase by 1 when I enter each record.
After I am continue working on project, when I add a record I saw that increment doesn't working correctly.
TABLE DEFINITION;
CREATE TABLE [dbo].[Urunler] (
[Urun_Id] INT IDENTITY (1, 1) NOT NULL,
[Referans_Kodu] VARCHAR (50) NULL,
[Urun_Tipi] VARCHAR (50) NULL,
[Urun_Adi] VARCHAR (150) NULL,
[Sertlik] VARCHAR (20) NULL,
[Birim] VARCHAR (20) NULL,
[Alan] DECIMAL (18, 2) NULL,
[Gramaj] DECIMAL (18, 3) NULL,
[Gunluk_Uretim] DECIMAL (18, 2) NULL,
[Fiyat] MONEY NULL,
[Doviz] VARCHAR (15) NULL,
[Vida_Hiz] DECIMAL (18, 2) NULL,
[Hat_Hiz] DECIMAL (18, 2) NULL,
[Notlar] VARCHAR (250) NULL,
PRIMARY KEY CLUSTERED ([Urun_Id] ASC)
);
I would have increase the ID by code but I am not sure it is the professional way to do it.
Upvotes: 0
Views: 65
Reputation: 5113
An autoincrement is just an arbitrary value that is generated sequentially, but nothing imposes on the system that this numbering is continuous, that is to say without any "hole".
"Holes" in auto increments occur when there is a ROLLBACK of a transaction, or the SQL Server service has been stopped. This is because, for efficiency reasons, a series of values of this auto increment is cached and this cache is lost in case of restart...
Upvotes: 2