Using Foreign Keys It is also possible to store the name of a database object such as a table or a column in a user variable and then to use this variable in an SQL statement; however, this requires the use of a prepared statement. See Section 13.5, “Prepared Statements” , for more information. In MySQL,  InnoDB  tables support checking of foreign key constraints. See Chapter 15,  The InnoDB Storage Engine , and Section 1.7.2.3, “FOREIGN KEY Constraint Differences” . A foreign key constraint is not required merely to join two tables. For storage engines other than  InnoDB , it is possible when defining a column to use a  REFERENCES  tbl_name ( col_name )  clause, which has no actual effect, and  serves only as a memo or comment to you that the column which you are currently defining is intended to refer to a column in another table . It is extremely important to realize when using this syntax that: You can use a column so created as a join column, as shown here: 3.6.6 Using Foreign Keys Note •MySQL does not perform any sort of check to make sure that  col_name  actually exists in  tbl_name  (or even that  tbl_name  itself exists). •MySQL does not perform any sort of action on  tbl_name  such as deleting rows in response to actions taken on rows in the table which you are defining; in other words, this syntax induces no  ON DELETE  or ON UPDATE  behavior whatsoever. (Although you can write an  ON DELETE  or  ON UPDATE  clause as part of the  REFERENCES  clause, it is also ignored.) •This syntax creates a  column ; it does  not  create any sort of index or key. CREATE TABLE person ( id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, name CHAR(60) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE shirt ( id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, style ENUM(’t-shirt’, ’polo’, ’dress’) NOT NULL, color ENUM(’red’, ’blue’, ’orange’, ’white’, ’black’) NOT NULL, owner SMALLINT UNSIGNED NOT NULL REFERENCES person(id), PRIMARY KEY (id) ); INSERT INTO person VALUES (NULL, ’Antonio Paz’); SELECT @last := LAST_INSERT_ID(); INSERT INTO shirt VALUES (NULL, ’polo’, ’blue’, @last), (NULL, ’dress’, ’white’, @last), (NULL, ’t-shirt’, ’blue’, @last); INSERT INTO person VALUES (NULL, ’Lilliana Angelovska’); SELECT @last := LAST_INSERT_ID(); INSERT INTO shirt VALUES (NULL, ’dress’, ’orange’, @last), (NULL, ’polo’, ’red’, @last), (NULL, ’dress’, ’blue’, @last), 331