0% found this document useful (0 votes)
14 views2 pages

Create Table Student

Uploaded by

duyhieuhoanglc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Create Table Student

Uploaded by

duyhieuhoanglc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATE TABLE student(

student_id char(8) NOT NULL,


first_name varchar(20) NOT NULL ,
last_name varchar(20) NOT NULL,
dob date NOT NULL,
gender char (1),
clazz_id char(8),
CONSTRAINT student_pk PRIMARY KEY (student_id),
CONSTRAINT student_gender CHECK (gender = 'F' OR gender='M'),
);

CREATE TABLE lecturer(


lecturer_id char(5) NOT NULL,
first_name varchar(20) NOT NULL,
last_name varchar(20) NOT NULL,
email varchar(40),
CONSTRAINT lecturer_pk PRIMARY KEY (lecturer_id)
);

CREATE TABLE clazz(


clazz_id char(8) NOT NULL,
name varchar(20),
lecturer_id char(5),
monitor_id char(8),
CONSTRAINT clazz_pk PRIMARY KEY (clazz_id),
CONSTRAINT clazz_fk_lecturer FOREIGN KEY (lecturer_id) REFERENCES
lecturer(lecturer_id),
CONSTRAINT clazz_fk_student FOREIGN KEY (monitor_id) REFERENCES
student(student_id)
);

ALTER TABLE student


ADD CONSTRAINT student_fk FOREIGN KEY(clazz_id) REFERENCES
clazz(clazz_id);

You might also like