How to use the keyword 'references' in MySQL?
Here is an example directly from MySQL website:
CREATE TABLE parent (id INT NOT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB;
CREATE TABLE child (id INT, parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id)
ON DELETE CASCADE
) ENGINE=INNODB;
Create the hobby table similarly to this:
CREATE TABLE hobby (
id INT NOT NULL AUTO_INCREMENT,
person_id INT NOT NULL,
hobby_name VARCHAR(255),
PRIMARY KEY(id),
FOREIGN KEY(person_id) REFERENCES person(id))