Identity Column | SansSQL

Friday, February 12, 2010

Identity Column

We all know about setting Identity to a column of a table.
By setting identity to a column, we mean that the column should be populated automatically by incrementing numbers based on the seed and increment option we give.
But all these days, i was setting the identity to a column of a table which had more than 2 columns.
Just think of having a table with only one column and setting identity to that Column.

Create Table IdentityTest
(Slno int identity(1,1))

When you run this query, it will create a table named IdentityTest with the column Slno with identity on it.
What next????
The next question would be, how to insert data to this table?
Any idea, on how to insert data to this table?
Here is how you insert data to this table..

Insert Into IdentityTest Default Values

And now after reading this post, you are now familiar with inserting data to a table which has only one column and identity set on it.  :)

1 comment:

Unknown said...

hey i didn't know that.. rather i didn't think of it.. good post.. :)

Post a Comment