Sunday, August 1, 2010

Insert Data into Indentityt column in a table having only one(identity Column)

I came across a very interesting scenario by a friend who had a recent job interview:

How to insert data into a table which has only one column and the column is an identity column

There are 2 options
1. Set Insert_identity ON
2. Use following query



create table Table1 (Col1 int identity(1,1))
go
insert into Table1 default values

select * from Table1

No comments:

Post a Comment