D
D
dNertyco2021-08-05 02:50:36
SQL
dNertyco, 2021-08-05 02:50:36

How to forbid creation of 2 records with any identical from two fields?

How to forbid creation of 2 records with any identical from two fields?
Let me explain
here there are entries
key1 key2
000 000 (identical - impossible)
001 000 (identical key2 - impossible)
000 002 (identical key1 - impossible)
234 012 (and so it is possible)
277 666 (and so it is possible)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2021-08-05
@res2001

Creation of records with the same value in one field is blocked by a unique index on this field.
Creation of records where key1 == key2 - can be blocked by a trigger.
Those. in your case, you need to create 2 unique indexes on key1 and key2 and a trigger for adding and changing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question