I have table that describes association of two other business models.
Example:
Construction Table - available constructions |
Reader Table - available readers |
ReaderPlacement Table - reader assigned to specific construction for specific time.
According to my requirements ReaderPlacement table must contains ApiKey, for me best match is unique GUID used later on for WCF communication.
I am planning to write something like this:
ApiKey CHAR(36) NOT NULL DEFAULT NewSequentialId()
Is it the right solution? I read that NewSequentialId() is better than NewId() and should be unique.
Does db engine will protect my column to be unique when I use NewSequentialId() or I have to add any constraint and additional checks ?
It must be also valid with SQL Azure.
Cheers,
Daniel
Just by defining a default of
newsequentialid(), there is no guarantee that you won’t have duplicates. Yes – the values generated by SQL Server will have an extremely high likelihood of being unique. But that default constraint doesn’t prevent you from inserting explicit values – and those could possibly collide with existing values.If your column
ApiKeyneeds to be unique at all times, you must add a unique constraintWith this unique constraint in place (which should definitely also work on SQL Azure), then SQL Server will prevent any duplicates from being inserted – any transaction attemting to do so will be terminated with an error message.