Hey Guys, I need a help with my SQL assignment, In your database, create a table
ID: 665174 • Letter: H
Question
Hey Guys, I need a help with my SQL assignment,
In your database, create a table called student. The table should have a student number, which is the primary key, and a student name.
Insert five records into your table.
Do a select statement on your table to show all the rows.
Add an attribute GPA, and provide values for each student. This attribute should not be allowed to be null.
Do a select on your table to show all of the rows.
Remove the attribute GPA from your table.
Remove one of the rows from your table.
Do a select on your table to show all of the rows.
Do a Select on your table to verify that GPA has been removed.
Drop your table.
Turn in a listing of your SQL statements and the records in your table.
Explanation / Answer
1.
CREATE TABLE student(studentNumber int, studentName varchar(20), PRIMARY KEY (studentNumber));
2.
INSERT INTO student values(1, 'NameA');
INSERT INTO student values(2, 'NameB');
INSERT INTO student values(3, 'NameC');
INSERT INTO student values(4, 'NameD');
INSERT INTO student values(5, 'NameE');
3.
SELECT * FROM students;
4.
ALTER TABLE student ADD GPA FLOAT;
UPDATE student SET GPA = 4.0 WHERE studentNumber = 1;
UPDATE student SET GPA = 3.0 WHERE studentNumber = 2;
UPDATE student SET GPA = 3.1 WHERE studentNumber = 3;
UPDATE student SET GPA = 3.5 WHERE studentNumber = 4;
UPDATE student SET GPA = 3.3 WHERE studentNumber = 5;
ALTER TABLE student MODIFY GPA FLOAT NOT NULL;