Create the following tables and add primary key constraint to students and cours
ID: 3768095 • Letter: C
Question
Create the following tables and add primary key constraint to students and courses tables.
Table Name: students
Id
Name
birth
gpa
Grad
1
Anderson
1987-10-2
3.9
2009
2
Jones
1990-04-16
2.4
2012
3
Hernandez
1989-08-12
3.1
2011
4
Chen
1990-02-04
3.2
2011
Table Name: courses
Id
Name
Number
quarter
1
CS142
CP II
Winter 2015
2
ART101
Finger painting
Fall 2014
3
ART101
Finger painting
Winter 2015
4
PE204
Mud wrestling
Winter 2015
Create a join table courses_students describing which students took which courses, and add primary key and foreign key constraints
course_id
student_id
1
1
3
1
4
1
1
2
2
2
1
3
2
4
4
4
Id
Name
birth
gpa
Grad
1
Anderson
1987-10-2
3.9
2009
2
Jones
1990-04-16
2.4
2012
3
Hernandez
1989-08-12
3.1
2011
4
Chen
1990-02-04
3.2
2011
Explanation / Answer
1. Create the following tables and add primary key constraint to students and courses tables.
CREATE TABLE students
(
Id int,
Name varchar(50),
birth Date,
gpa Number(4,2),
Grad int,
PRIMARY KEY (Id)
);
CREATE TABLE courses
(
Id int,
Name varchar(50),
Number varchar(20),
quater varchar(20),
PRIMARY KEY (Id)
);
2. Create a join table courses_students describing which students took which courses, and add primary key and foreign key constraints
Create Table courses_students
(
course_id int,
student_id int,
PRIMARY KEY (course_id,student_id),
FOREIGN KEY (course_id) REFERENCES students(Id),
FOREIGN KEY (student_id) REFERENCES courses(Id),
);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.