Suppose I have a
table User(userid, usernama) and a
table Owner(ownerid, ownername) and a joined
table UserOwnerMapping(userid, ownerid, IS_MASTER)
which create a many-to-many between user and owner
The is_master default is ‘N’. A user can only has one master.
How can I used a constraint to force no more than one master
for a user?
I am using Oracle.
You can achieve the constraint using a unique function-based index:
This will only index the userid when is_master = ‘Y’, so forces userid to be unique when is_master = ‘Y’ but not otherwise: