3.18
Give an SQL schema definition for the employee database of Figure 3.19. Choose an appropriate domain for each attribute and an appropriate primary key for each relation schema. Include any foreign-key constraints that might be appropriate.
CREATE TABLE employee (
id VARCHAR(8),
VARCHAR(30) NOT NULL,
person_name VARCHAR(40),
street VARCHAR(30),
city PRIMARY KEY (id)
);
CREATE TABLE company (
VARCHAR(40),
company_name VARCHAR(30),
city PRIMARY KEY (company_name)
);
CREATE TABLE works (
id VARCHAR(8),
VARCHAR(40),
company_name NUMERIC(10,2) CHECK (salary > 10000),
salary PRIMARY KEY (id),
FOREIGN KEY (id) REFERENCES employee(id)
ON DELETE CASCADE,
FOREIGN KEY (company_name) REFERENCES company(company_name)
ON DELETE CASCADE
);
CREATE TABLE manages (
id VARCHAR(8),
VARCHAR(8),
manager_id PRIMARY KEY (id),
FOREIGN KEY (id) REFERENCES employee (id),
FOREIGN KEY (manager_id) REFERENCES employee (id)
);