Lab Assignment 2 – With Answer Key ✅
Date: 13.10.2025 (10:40 – 12:30) 📅
Create a database called UniversityDB -1
:Answer
;CREATE DATABASE UniversityDB
:Create a relation called Students that contains -2
.StudentID as integer such that it is a primary key
StudentName as string of at most 50 characters
BirthDate as date
GPA as a float that accepts 2 digits after the decimal point and up to 3 digits before
it
MajorID as integer
Year as integer with default value = 1
:Answer
( CREATE TABLE Students
,StudentID INT PRIMARY KEY
,StudentName VARCHAR(50)
,BirthDate DATE
,GPA NUMERIC(5,2)
,MajorID INT
Year INT DEFAULT 1
;)
:Write suitable SQL statements for doing the following tasks -3
a) Insert the following 4 tuples into the Students relation such that the Year values should
:not be inserted
StudentID StudentName BirthDate GPA MajorID Year
2002-04-
201 Zeynep Korkmaz 3.45 10 1
18
2001-11-
202 Emre Yıldız 2.80 NULL 1
05
2003-06-
203 Hakan Tunç NULL 20 1
12
2002-01-
204 Derya Aydın 3.90 30 1
22
:Answer
INSERT INTO Students (StudentID, StudentName, BirthDate, GPA, MajorID)
VALUES
,)Zeynep Korkmaz', '2002-04-18', 3.45, 10' ,201(
,)Emre Yıldız', '2001-11-05', 2.80, NULL' ,202(
,)Hakan Tunç', '2003-06-12', NULL, 20' ,203(
;)Derya Aydın', '2002-01-22', 3.90, 30' ,204(
b) Insert another student with only the ID “205” and the name “Bora A.” Do not use NULL
.values in the insertion
:Answer
INSERT INTO Students (StudentID, StudentName, BirthDate, GPA, MajorID, Year)
;VALUES (205, 'Bora A.', '2000-01-01', 0.00, 0, 1)
Not: Doğrudan NULL kullanılmaması gerektiği için uygun default (0, 0.00, '2000-01-01'
.gibi) değerler girildi
.c) Change all NULL values in GPA to 2.50
:Answer
UPDATE Students
SET GPA = 2.50
;WHERE GPA IS NULL
.d) Change Hakan Tunç’s Year to 2 and his MajorID to 25
:Answer
UPDATE Students
SET Year = 2, MajorID = 25
;'WHERE StudentName = 'Hakan Tunç
.e) Add a new column called Email as a string of at most 40 characters
:Answer
ALTER TABLE Students
;ADD Email VARCHAR(40)
.f) Rename the table Students to Learners
:Answer
ALTER TABLE Students
;RENAME TO Learners
.g) Change the column name GPA to CGPA
:Answer
ALTER TABLE Learners
;RENAME COLUMN GPA TO CGPA
h) Delete all learners whose Year = 1
:Answer
DELETE FROM Learners
;WHERE Year = 1