xarzu
xarzu

Reputation: 9479

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)
)

Upvotes: 73

Views: 126559

Answers (3)

ASMAR CSE
ASMAR CSE

Reputation: 11

In sql when we create a table there we define few things ex- create table tbl_employee ( id primary key identity(1,1) name varchar(50), age int, mobileno bigint )

identity (1,1):- identity is the property for auto increment, but when we put condition(1,1) then it means identity will start from 1 and will increase by 1 ex-1 2 3 4, but when we put different condition like (4,3) it will show it will start from 4 and increase by 3 Ex- 4 7 10 13 just like arithmetic progression(AP)

Upvotes: 1

itzmebibin
itzmebibin

Reputation: 9439

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,...

Upvotes: 106

Lukasz Szozda
Lukasz Szozda

Reputation: 175646

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

Upvotes: 29

Related Questions