I
I
Ivan Melnikov2019-10-30 10:51:19
Database design
Ivan Melnikov, 2019-10-30 10:51:19

Are there such a thing as a conditional unique index in any DBMS?

A conditional unique index could:
1) ensure that values ​​in a field are unique for each unique value in an adjacent table field (solution: composite unique index);
2) ensure the uniqueness of the values ​​in the field for each unique value in some field of the parent table.
For example, there are two tables:
5db93fc070443303286956.png
I need to ensure that the addr field in the Line table is unique , not just unique (addresses in different cities can be the same), but unique for each unique value in the city_id field of the Group table . Is it possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Decadal, 2019-10-30
@Decadal

You can make a Composite Unique Key on the fields addr, city_id or addr and group_id
For example:
in case you need some information from another table, your database probably needs some extra normalization. You should not restrict writing to one table based on any values ​​from the related table, because then there is an ambiguous relationship

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question