Identity column specifies when ever new value is inserted
into table. Identity column automatically inserted value into column.
Identity Column can be specified at the time of creation of
table.
CREATE TABLE Employee
(
EMPID INT IDENTITY(1,1),
EMPNAME VARCHAR(50),
SALARY INT
)
In above table creation script EMPID column specifies
IDENTITY property i.e., whenever a new row inserted into a Employee table EMPID
Column will automatically value is inserted.
INSERT INTO Employee (EMPNAME,SALARY)VALUES('RAKESH',7000)
INSERT INTO Employee (EMPNAME,SALARY)VALUES('ALI',12000)
SELECT * FROM Employee
When u run above select statement is the following result
is
if u are trying insert
value into identify columns .it will give error.
INSERT INTO Employee (EMPID,EMPNAME,SALARY)VALUES(1,'RAKESH',7000)
Msg
544, Level 16, State 1, Line 1
Cannot
insert explicit value for identity column in table 'Employee' when
IDENTITY_INSERT is set to OFF.
Comments
Post a Comment