What's difference between IDENTITY and IDENTITY(1,1) in SQL?
CREATE TABLE tblSample
(
UID INT NOT NULL IDENTITY,
FName NVARCHAR(250),
LName NVARCHAR(250)
);
CREATE TABLE tblSample
(
UID INT NOT NULL IDENTITY(1,1),
FName NVARCHAR(250),
LName NVARCHAR(250)
);
Naimish MakwanaPosted Feb 25, 2023, 11:56 AM
Hello Manikandan,
The IDENTITY property is used to automatically generate unique values for a column. When you specify a column as an IDENTITY column, the values are generated automatically by SQL Server when a new row is inserted into the table.
The difference between
IDENTITYandIDENTITY(1,1)lies in the seed and increment values that you can optionally specify withIDENTITY(1,1).IDENTITY: If you use the IDENTITY property without specifying seed and increment values, SQL Server will use default values of (1,1) for the seed and increment, respectively. This means that the first value generated will be 1, and each subsequent value will be incremented by 1.IDENTITY(1,1): If you specifyIDENTITY(1,1), you are explicitly setting the seed and increment values to 1. This is the same as usingIDENTITYwithout any arguments, but it makes it clear that you have specified the default values.For more if you specify with
IDENTITY(1,2).IDENTITY(1,2): If you specifyIDENTITY(1,2), you are explicitly setting the seed value to 1 and the increment value to 2. This means that the first value generated will be 1, the second value will be 3, the third value will be 5, and so on.Thanks
Naimish Makwana
Rajeev KumarPosted Mar 2, 2023, 1:24 PM
difference between IDENTITY and IDENTITY(1,1)
In IDENTITY() You do'nt pass a value it set automatically identity seed=1 and increment value is also 1.If you specify
IDENTITY(1,1), you are explicitly setting the seed and increment values to 1. This is the same as usingIDENTITYwithout any arguments.Manikandan RPosted Feb 25, 2023, 1:23 PM
Thank you.