I have two tables, one "master" and one "children's" table. Each table has a "ProductNo" field, which is defined as PRIMARY KEY and UNIQUE. Is it possible to define the field "ProductNo" in the table "child" and the same field in the table "master" as PRIMARY + UNIQUE together?
master:
ID | ProductNo
child:
ID | MasterID (FK on master.ID) | ProductNo
Relation >> 1 (master) : n (child)
example data:
master:
1 | 1234
2 | 4567
child:
100 | 1 | 3333
101 | 1 | 4444
102 | 2 | 5555
103 | 1 | 1234 <----- NOT ALLOWED! PRODUCT NO ALREADY EXISTING IN TABLE `MASTER`
104 | 2 | 1234 <----- NOT ALLOWED! PRODUCT NO ALREADY EXISTING IN TABLE `MASTER`
You need to check to insert / update the table "child" if "ProductNo" already exists in the table "master".
How can I identify it? Or do I need to create a trigger for this?
TIA Matt
source
share