30 likes | 89 Views
For student, require values for name and address. For advisor, require values for name, phone, and email. For advisor, make values for email unique. SQL DDL Example. CREATE TABLE student (pid varchar(9), name varchar(25) NOT NULL, address varchar(50) NOT NULL, phone varchar(15),
E N D
For student, require values for name and address. For advisor, require values for name, phone, and email. For advisor, make values for email unique.
SQL DDL Example CREATE TABLE student (pid varchar(9), name varchar(25) NOT NULL, address varchar(50) NOT NULL, phone varchar(15), email varchar(25), PRIMARY KEY (pid)); CREATE TABLE advisor (emp_id varchar(5) CONSTRAINT pk_adv PRIMARY KEY, name varchar(25) NOT NULL, office varchar(25), phone varchar(6) NOT NULL, email varchar(25) NOT NULL, UNIQUE (email));
SQL DDL Example CREATE TABLE st_adv (pid varchar(9) CONTRAINT fk_st REFERENCES student(pid) ON DELETE CASCADE ON UPDATE CASCADE, emp_id varchar(5), PRIMARY KEY (pid, emp_id), FOREIGN KEY (emp_id) REFERENCES advisor(emp_id) ON DELETE CASCADE ON UPDATE CASCADE; CREATE INDEX sid_x ON student(pid); CREATE INDEX emp_x ON advisor(emp_id); CREATE INDEX adv_stx ON st_adv(pid, emp_id);