syntax to reference foreign key : Add Foreign Key « Constraints « Oracle PL / SQL






syntax to reference foreign key

    
SQL>
SQL>
SQL> --CREATE TABLE <table schema> OF <object schema>
SQL> --   (key attribute    NOT NULL,
SQL> --    attribute        attribute type,
SQL> --    PRIMARY KEY      (key attribute),
SQL> --    FOREIGN KEY      (key attribute)
SQL> --    REFERENCES <referenced table schema>(key attribute)
SQL> --    [ON DELETE][CASCADE|SET NULL]);
SQL>
SQL> --Example:
SQL>
SQL> CREATE TABLE emp
  2      (id         VARCHAR2(10) NOT NULL,
  3       course     VARCHAR2(10),
  4       year       VARCHAR2(4),
  5       PRIMARY KEY (id),
  6       FOREIGN KEY (id) REFERENCES Person ON DELETE CASCADE);



SQL>     FOREIGN KEY (id) REFERENCES Person ON DELETE CASCADE)
SP2-0734: unknown command beginning "FOREIGN KE..." - rest of line ignored.
SQL>
SQL>
SQL>
SQL>

   
    
    
    
  








Related examples in the same category

1.Add Foreign Primary Key
2.Alter table to add primary key and alter another table to add foreign key
3.Many to many using a primary-key and foreign-key relationship
4.Three foreign keys in a table
5.One to many using a primary-key and foreign-key relationship