In MS SQL is it possible to share an identity seed across tables? For example I may have 2 tables:
Table: PeopleA
- id
- name
Table: PeopleB
- id
- name
I’d like for PeopleA.id and PeopleB.id to always have unique values between themselves. I.e. I want them to share the same Identity seed.
Note: I do not want to hear about table partitioning please, only about if it’s possible to share a seed across tables.
No, but I guess you could create an IDENTITY(1, 2) on the one table and an IDENTITY(2, 2) on the other. It’s not a very robust design though.
Could you instead refer to your entities as ‘A1’, ‘A2’, … if they come from TableA and ‘B1’, ‘B2’, etc… if they come from TableB? Then it’s impossible to get duplicates. Obviously you don’t actually need to store the A and the B in the database as it is implied.