cortextual
Technical User
I'm working with a database that was designed by someone else. I think he made a mistake setting up some tables and relationships, and I would really appreciate any suggestions on how to fix them!
I have two tables, called Modules and Costs. The Modules table should be the parent and it has the primary key ID, Module, and Type. The Costs table has the primary key ID, a foreign key CompanyID, Subscription, Type, and Cost. Under relationships two tables are connected by Module to Subscription and by Type to Type. When I try to enforce referential integrity I get the message "no unique index found for the referenced field of the primary table."
I think the issue is that in the Modules table there are a few modules with the same name, but they have different types. That would have been fine if he'd linked the table through the Modules primary key (put a ModuleID field into the Costs table) but he didn't. I see two options:
- best case scenario would be if I could add the ModuleID foreign key field to the Costs table now, but there are 1600 records in the table so I would need them to autofill correctly (by referencing both the subscription name and type) and I don't know how to do that/ if it's possible.
- alternatively I'm thinking that if I modify the module names in the Modules table to be unique then manually change them in the Costs table I'll then be able to enforce referential integrity. Given the number of records I'd like to avoid this option unless I can be 100% sure it'll work.
Any ideas? I'm a fairly new access user so I wouldn't be surprised if there's something obvious I missed, but I haven't found anything helpful online. The end result I'm looking for is to enforce referential integrity and cascade updates between the tables so if in the future a module name has to be changed it will also change that subscription name in the Costs table.
I have two tables, called Modules and Costs. The Modules table should be the parent and it has the primary key ID, Module, and Type. The Costs table has the primary key ID, a foreign key CompanyID, Subscription, Type, and Cost. Under relationships two tables are connected by Module to Subscription and by Type to Type. When I try to enforce referential integrity I get the message "no unique index found for the referenced field of the primary table."
I think the issue is that in the Modules table there are a few modules with the same name, but they have different types. That would have been fine if he'd linked the table through the Modules primary key (put a ModuleID field into the Costs table) but he didn't. I see two options:
- best case scenario would be if I could add the ModuleID foreign key field to the Costs table now, but there are 1600 records in the table so I would need them to autofill correctly (by referencing both the subscription name and type) and I don't know how to do that/ if it's possible.
- alternatively I'm thinking that if I modify the module names in the Modules table to be unique then manually change them in the Costs table I'll then be able to enforce referential integrity. Given the number of records I'd like to avoid this option unless I can be 100% sure it'll work.
Any ideas? I'm a fairly new access user so I wouldn't be surprised if there's something obvious I missed, but I haven't found anything helpful online. The end result I'm looking for is to enforce referential integrity and cascade updates between the tables so if in the future a module name has to be changed it will also change that subscription name in the Costs table.