Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 758 Bytes

6-buildtable_challenge.md

File metadata and controls

36 lines (26 loc) · 758 Bytes

<<< Back - Next >>>

Challenge: build a table for GPA!

Let's imagine that we want to connect each student to their GPA. How can we do this?

Things to consider:

  • Where will we put the GPAs?
  • What kind of data type will they be?
  • How will we connect each GPA to the correct student?

Solution

Create a New Table For GPAs

CREATE TABLE gpas (
	id INTEGER PRIMARY KEY,
	gpa DOUBLE PRECISION,
	id_student INTEGER,
	FOREIGN KEY (id_student) REFERENCES students(id)
);

Populate the GPA Table with GPA Score and Foreign Key

INSERT INTO gpas (gpa, id_student) VALUES
	(2.67, 2),
	(3.9, 1),
	(1.23, 3),
	(4.0, 4);

<<< Back - Next >>>