Is there a way to create a unique index across tables in a SQL Server database?
I have two tables, Table A and Table B. In that I have a Column named ID, I want to make these Id columns as unique (combining Table A and B's Ids )
How can I do this ?
indexsql serverunique-constraint
Is there a way to create a unique index across tables in a SQL Server database?
I have two tables, Table A and Table B. In that I have a Column named ID, I want to make these Id columns as unique (combining Table A and B's Ids )
How can I do this ?
Best Answer
You could use a sequence for generating the values for ID fields. The documentation explicitly mentions your use case. The example C on said page has a sample implementation about this.
Be aware that there are a few catches. For example, sequence values are reusable, are not unique by default and can contain gaps. Pay attention to the Limits part in the docs.