SEQUENCE in ORACLE vs IDENTITY in SQL Server

  • Like we have SEQUENCE in Oracle.. We have IDENTITY in SQL SERVER.

    I am in a situation where I have three similar tables but different ennough that i wann keep them inthree different tables. But i want them in a sequnce.

    Example:

    If i insert 10 records into TABLE_A then the ID column of that table should have values from 1 to 10

    Then if i insert a record into TABLE_B the ID column in that tbale shoudl be 11

    Then if i insert 5 records into TABLE_C the ID column in that table should be from 12-17

    So bacially what I am trying to accomplish here is using same IDENTITY across n number of tables.

    Is it possible ? If so how ?

    If not is there any other alternative.

    Thank You Folks

    [font="Verdana"]
    Today is the tomorrow you worried about yesterday:-)
    [/font]

  • Unlike a sequence, which is a database object, identity is a column property which can't be shared among tables.

    You could could do what you want by creating a table with a single integer column. Each time you insert a row into any of the tables (TABLE_A, TABLE_B, TABLE_C), you select the value from the number table and use it for the ID then update the number table to increment by 1.

    Greg

  • Got it. Thank You.

    [font="Verdana"]
    Today is the tomorrow you worried about yesterday:-)
    [/font]

  • @celko

    Thanks for the info it was very helpful.

    Well i know placing similar data into three different tables has nothing to do with RDBMS. But it was a compromise. I had to fix soemthing. I gave up on the idea of redesigning the schema structure of my 30 year old company.

    [font="Verdana"]
    Today is the tomorrow you worried about yesterday:-)
    [/font]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply