Relating tables

From: <bucaliman_at_gmail.com>
Date: 7 Apr 2006 10:47:20 -0700
Message-ID: <1144432040.929016.141910_at_i39g2000cwa.googlegroups.com>



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 - 19:47:20 CEST

Original text of this message