I'm in the process of migrating data to an SQL server database, ideally going foward I want to use the tables in this database to generate unique identities for the data being recorded in them, however the existing data comes with unique identities already.
I'd like to set up a table that looks like this
entry_num (PK) | component (FK) | long_id (Unique) - computed from combining row_num and component |
---|---|---|
1 | THING1 | THING1_1 |
2 | THING2 | THING2_2 |
3 | THING1 | THING2_3 |
I would like to be able to insert my existing data into the table by including it's existing id in the long_id column, and for future entries calculate the column automatically.
So my original inserted data might look like this:
entry_num (PK) | component (FK) | long_id (Unique) - computed from combining row_num and component |
---|---|---|
1 | THING2 | THING2_50 |
2 | THING3 | THING3_90 |
3 | THING4 | THING4_11 |
Alternatively could I manually specify the entry_num to match the identities?
I was planning on using
CREATE TABLE table_name (entry_num int IDENTITY...);
to auto increment this column, but is there another way that allows me to manually alter the identities of specific rows without violating the auto incrementing ability?