sql server - Ensuring no duplicates without unique constraint -
is possible ensure column doesn't contain duplicate values without using unique constraint (don't want go in reasons why being avoided) on column? in particular thinking of race conditions.
for sake of simplicity let's column in question of type nvarchar(50)
(does type matter?)
it possible trigger, condition if not exists(...
before insert. in fact unique constraint
fastest.
another option create unique index on column , supposed faster trigger , condition.
if don't want add unique constraint existing table, can create additional table field nvarchar (50)
, unique constraint on it. , insert value of field in new table before insert in main table in transaction (inside insert statement or in trigger).
Comments
Post a Comment