20 likes | 165 Vues
This SQL code defines the structure for the Employee table (EMP) with multiple constraints to ensure data integrity. The table includes columns for employee name (ENAME), social security number (ESSN), birth date (BDATE), department number (DNO), and supervisor's social security number (SUPERSSN). It enforces primary key on the ESSN column and establishes foreign key relationships with the Department (DNO) and supervisor (SUPERSSN) with specific actions on delete and update to maintain referential integrity.
E N D
REFERENTIAL INTEGRITY CREATE TABLE EMP (ENAME VARCHAR(30) NOT NULL, ESSN CHAR(9), BDATE DATE, DNO INTEGER DEFAULT 1, SUPERSSN CHAR(9), PRIMARY KEY (ESSN), FOREIGN KEY (DNO) REFERENCES DEPT(Dnm) ON DELETE SET DEFAULT ON UPDATE CASCADE, FOREIGN KEY (SUPERSSN) REFERENCES EMP(ssn) ON DELETE SET NULL ON UPDATE CASCADE );