我将 URL 存储在具有 varchar(4000) 数据类型的列中。我想对该列强制执行唯一性约束,但无法这样做,因为 4000 远远超出了最大限制。
有没有办法在这些列上强制执行唯一性?
我将 URL 存储在具有 varchar(4000) 数据类型的列中。我想对该列强制执行唯一性约束,但无法这样做,因为 4000 远远超出了最大限制。
有没有办法在这些列上强制执行唯一性?
The uniqueness of that long fields is not enforcable by use of indices.
The right way is likely to perform a select inside a trigger before insert/update and failing for a value that is already contained in the column.
A practicable workaround at the application level or inside a stored procedure may be to perform a select for the new value followed by an insert (if that value is not already present) inside a transaction.
In any case, part of the column in question shoud be (non-uniquely) indexed to speed the select.