Use a FOREIGN KEY constraint to define the foreign key : Foreign Key « Key « SQL / MySQL






Use a FOREIGN KEY constraint to define the foreign key

      
mysql>
mysql> CREATE TABLE Orders
    -> (
    ->     OrderID SMALLINT UNSIGNED NOT NULL PRIMARY KEY,
    ->     ModelID SMALLINT UNSIGNED NOT NULL,
    ->     ModelDescrip VARCHAR(40),
    ->     FOREIGN KEY (ModelID) REFERENCES Models (ModelID) ON DELETE CASCADE ON UPDATE CASCADE
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>

   
    
    
    
    
    
  








Related examples in the same category

1.Define foreign key
2.RESTRICT update and delete
3.Add Foreign Key Rules
4.Add the foreign key by using the following
5.Reference foreign key
6.Two foreign keys
7.On delete set null
8.Cascade delete