![]() Then, add a trigger (as shown in this answer) to ensure that all but one of these values is NULL. You could create the group_device table with a unique column for each possible device type ( device_typeA_id, device_typeB_id, device_typeC_id, etc.). Multiple columns in group_device (don't use) This does involve a certain amount of maintenance pain - when a new device is added, you have to create two tables ( device_typeN and group_device_typeN), plus you have to modify the group_device view. You could find a way to create a unique ID across the actual group_device_* tables if absolutely required, but that's a bit more work. id column (the other three columns should uniquely identify a row). You can create a group_device view that's basically the same as the current group_device table. Have a unique table linking each type of device to the appropriate group ( group_device_typeA, group_device_typeB, group_device_typeC, etc.). You have a few options: Multiple group_device tables So id_device in group_device cannot be a foreign key to all three device tables. My problem is the id_device column, that is relative to multiple tables (devices_typeA.id, devices_typeB.id, devices_typeC.id).Ī declared foreign key (i.e., one enforced by the database engine) cannot tie to multiple other tables. Now i would like to add some foreign key to the tables group_device (in such a way that when a device is deleted, is deleted also in the table group_device ). Group_device id | type_device | id_device | id_group | ![]() Id is primary key id | column1 | column2 | column2 | columnN | Id is primary key id | column1 | column2 | I have some tables relative to different type of devices (different tables because the "devices" are completely different from each other), a table groups and a relation-table group_device (the same device can be in more groups). I'm trying to improve the database integrity adding some foreign key (it's the first time i use them).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |