Thursday 23 July 2015

T-SQL interview question Identity Column

1) If a table is having only one identity column how can we insert records into this table?
Answer :

Consider table customer which is created with below statement in sql server
create table customer
( id int identity(1,1))
Now to insert  records into this table we can do it in two ways:
a) INSERT INTO customer DEFAULT VALUES
b)
SET IDENTITY_INSERT dbo.customer ON
INSERT INTO customer (id)
values (1),(2),(3)

No comments:

Post a Comment