Declaring a Foreign Key : Create Foreign Key « Constraints « Oracle PL / SQL






Declaring a Foreign Key

  
SQL>
SQL>
SQL> CREATE TABLE myTable (myTableID INT PRIMARY KEY NOT NULL,
  2                       Name VARCHAR(50));

Table created.

SQL>
SQL> CREATE TABLE Phone (
  2     PhoneID INT PRIMARY KEY NOT NULL,
  3     myTableID INT,
  4     PhoneNo VARCHAR(20),
  5     CONSTRAINT FID_FK FOREIGN KEY(myTableID)
  6        REFERENCES myTable(myTableID));

Table created.

   
    
  








Related examples in the same category

1.Create table with foreign key
2.Create a foreign key with more than one field
3.Referential Integrity Constraints
4.Add constraint foreign key references
5.Violate a foreign key