Reference column from another column : References « Table « Oracle PL/SQL Tutorial






SQL>
SQL> CREATE TABLE compact_discs (
  2     ID      INTEGER NOT NULL,
  3     title   VARCHAR2(60),
  4     artist  VARCHAR2(60),
  5     label   VARCHAR2(60),
  6     PRIMARY KEY (ID)
  7  );

Table created.

SQL>
SQL> INSERT INTO compact_discs VALUES (100, 'W', 'B', 'A');

1 row created.

SQL>
SQL> CREATE TABLE cd_keywords (
  2     cd_id        INTEGER NOT NULL REFERENCES compact_discs (id),
  3     keyword      VARCHAR2(60) NOT NULL,
  4     PRIMARY KEY  (cd_id, keyword)
  5  );

Table created.

SQL>
SQL> INSERT INTO cd_keywords VALUES (100, 'L');

1 row created.

SQL> INSERT INTO cd_keywords VALUES (100, 'M');

1 row created.

SQL>
SQL> drop table cd_keywords;

Table dropped.

SQL> drop table compact_discs;

Table dropped.

SQL>








6.17.References
6.17.1.Refernece a table
6.17.2.Reference column from another column