| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Relating tables
Hello database experts! Please could you help to relate these tables?
One user can have many companies. Each company may have many employees.
USERS
idusers (PK)
COMPANIES
idcompanies (PK)
users_idusers (FK)
EMPLOYEES
idemployees (PK)
companies_idcompanies (FK)
USERS and COMPANIES are linked.
I did this to link COMPANIES and EMPLOYEES:
ALTER TABLE `employees` ADD CONSTRAINT `employees_fk` FOREIGN KEY ( `companies_idcompanies` ) REFERENCES `companies` ( `idcompanies` ) ON DELETE CASCADE ON UPDATE CASCADE I got this error: Cannot add or update a child row: a foreign key constraint fails. Received on Fri Apr 07 2006 - 12:47:20 CDT
![]() |
![]() |