Two foreign keys
mysql>
mysql>
mysql> CREATE TABLE EmployeeS(
-> EmployeeNO INTEGER NOT NULL,
-> NAME CHAR(15) NOT NULL,
-> INITIALS CHAR(3) NOT NULL,
-> BIRTH_DATE DATE ,
-> SEX CHAR(1) NOT NULL,
-> JOINED SMALLINT NOT NULL,
-> STREET VARCHAR(30) NOT NULL,
-> HOUSENO CHAR(4) ,
-> POSTCODE CHAR(6) ,
-> TOWN VARCHAR(30) NOT NULL,
-> PHONENO CHAR(13) ,
-> LEAGUENO CHAR(4) ,
-> PRIMARY KEY (EmployeeNO) );
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> CREATE TABLE TEAMS
-> (TEAMNO INTEGER NOT NULL,
-> EmployeeNO INTEGER NOT NULL,
-> DIVISION CHAR(6) NOT NULL,
-> PRIMARY KEY (TEAMNO),
-> FOREIGN KEY (EmployeeNO) REFERENCES EmployeeS (EmployeeNO));
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> CREATE TABLE MATCHES
-> (MATCHNO INTEGER NOT NULL,
-> TEAMNO INTEGER NOT NULL,
-> EmployeeNO INTEGER NOT NULL,
-> WON INTEGER NOT NULL,
-> LOST INTEGER NOT NULL,
-> PRIMARY KEY (MATCHNO),
-> FOREIGN KEY (TEAMNO) REFERENCES TEAMS (TEAMNO),
-> FOREIGN KEY (EmployeeNO) REFERENCES EmployeeS (EmployeeNO));
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql>
Related examples in the same category