Enforcing Referential Activity in a New Table

Enforce referential integrity in a new table.

  1. Create the primary table, for example:
    CREATE TABLE DEPT(DeptNo int primary key,
    DeptName varchar(20),
    Mgr int );
  2. Create the foreign table. For example, in this statement, the default role name for the specified foreign key is DEPT:
    CREATE TABLE EMPLOYEE(EmpNo int primary key,
    DeptNo int REFERENCES DEPT(DeptNo)
    ON DELETE RESTRICT,
    LastName varchar(20),
    FirstName varchar(20),
    Salary int);
  3. Specify the foreign key constraint. For example:
    ALTER TABLE DEPT ADD FOREIGN KEY EMP_DEPT(DeptNo)
    REFERENCES DEPT(DeptNo);

    In this statement, the user specified role name for the same foreign key is EMP_DEPT.