Pages

Tuesday, April 28, 2009

Oracle Sequence Vs IDENTITY in SQL Server

I am getting so many mails on what is the equivalent of Oracle Sequence in SQL Server?

There is nothing like equivalent of Oracle Sequence in SQL Server. At the same time IDENTITY can not be compared with Sequence in Oracle. All though there is a feature called IDENTITY to produce unique numbers.

Both are very unique and useful features in each of the databases.

Oracle Sequence Advantages:
1) Standalone object any one can use it for any column.
2) This is not tightly coupled with any column so one can easily drop this object.
3) One can easily insert the data into Sequence related column.
4) You can use the same sequence to populate multiple columns in the same table.
5) You need to explicitly use Sequence Name during inserts.


SQL Server IDENTITY Advantages:
1) IDENTITY is a property which is tightly coupled with column in a table.
2) This is tightly coupled with column so you can’t drop this property. The only way to drop IDENTITY property is to drop the column itself.
3) To insert the data into IDENTITY column you need to set a flag.
4) You can have only one column per table with the IDENTITY property.
5) You need to skip the IDENTITY column during inserts.

Keep watching for more information on IDENTITY in SQL Server.

7 comments:

Raghu said...

Good Comparision. Good way to explain about the features of the databases.

Anonymous said...

Thanks for this article.It explains the comparisons very well.

Martin Vanek said...

Oracle sequence is not transactional. It's value is not restored after transaction rollback.

Unknown said...

You can also use triggers with a sequence to achieve virtually the same kind of functionality as an identity.

Frankly, I don't see any advantage with identities. I think they're stupid. Sequences are far more flexible.

vikrantmanne said...

thanks for sharing the info.

Neel said...

ithout making this into a religious discussion, a major one benefit of identity for example is concurrency control. Incorporating non-composite keys into data models is so much easier than having to deal with sequences in code.

Cheers,
Neel

Anonymous said...

How do find out, which column is using a sequence (identity)?