One to many using a primary-key and foreign-key relationship : Add Foreign Key « Constraints « Oracle PL / SQL






One to many using a primary-key and foreign-key relationship

    
SQL>
SQL>
SQL> CREATE TABLE Programmer
  2     (lect_id    VARCHAR2(10) NOT NULL,
  3      lect_name  VARCHAR2(20),
  4      PRIMARY KEY (lect_id));

Table created.

SQL>
SQL> CREATE TABLE Course
  2     (course_id        VARCHAR2(10) NOT NULL,
  3      course_name      VARCHAR2(20),
  4      lect_id          VARCHAR(10),
  5      PRIMARY KEY (course_id),
  6      FOREIGN KEY (lect_id) REFERENCES Programmer (lect_id)
  7      ON DELETE CASCADE);

Table created.

SQL>
SQL> drop table Programmer cascade constraints;

Table dropped.

SQL> drop table Course cascade constraints;

Table dropped.

   
    
    
    
  








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.syntax to reference foreign key
4.Many to many using a primary-key and foreign-key relationship
5.Three foreign keys in a table