What does (1,1) mean in SQL?
What does (1,1) mean in SQL? I mean in the following context:
create table PetOwner
(
Id int identity(1,1)
, Name nvarchar(200)
, Policy varchar(40)
)
In Id int identity(1,1)
, the first 1 means the starting value of ID and the second 1 means the increment value of ID. It will increment like 1,2,3,4.. If it was (5,2), then, it starts from 5 and increment by 2 like, 5,7,9,11,...
SQL Server
IDENTITY
column:
IDENTITY [ (seed , increment) ]
Identity columns can be used for generating key values. The identity property on a column guarantees the following:
Each new value is generated based on the current seed & increment.
Each new value for a particular transaction is different from other concurrent transactions on the table.
Start from 1 with step 1.
Very convenient way to generate "consecutive" numbers. Please note that:
Reuse of values – For a given identity property with specific seed/increment, the identity values are not reused by the engine. If a particular insert statement fails or if the insert statement is rolled back then the consumed identity values are lost and will not be generated again. This can result in gaps when the subsequent identity values are generated.
create table #PetOwner(
Id int identity(1,1)
, Name nvarchar(200)
, Policy varchar(40));
INSERT INTO #petOwner(Name, Policy)
VALUES ('Tim', 'a'),('Bob' ,'b');
SELECT *
FROM #PetOwner;
LiveDemo