0% found this document useful (0 votes)
24 views5 pages

DBMS With NO SQL Lab

The document outlines the SQL implementation of a university database, including tables for Students, Courses, Professors, and their relationships through Teaches and Enrolls. It also provides sample data insertion and basic queries to find courses taught by specific professors and to calculate average GPAs. Additionally, it discusses normalizing an unnormalized schema into three distinct tables and compares query performance across these tables.
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)
24 views5 pages

DBMS With NO SQL Lab

The document outlines the SQL implementation of a university database, including tables for Students, Courses, Professors, and their relationships through Teaches and Enrolls. It also provides sample data insertion and basic queries to find courses taught by specific professors and to calculate average GPAs. Additionally, it discusses normalizing an unnormalized schema into three distinct tables and compares query performance across these tables.
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/ 5

Program-1:

SQL Implementation:

CREATE TABLE Student (

StudentID INT PRIMARY KEY,

Name VARCHAR(50),

Address VARCHAR(100),

Phone VARCHAR(20),

Major VARCHAR(50),

GPA DECIMAL(3,2)

);
CREATE TABLE Course (

CourseID INT PRIMARY KEY,

CourseName VARCHAR(100),

Credits INT,

Prerequisites VARCHAR(100)

);

CREATE TABLE Professor (

ProfessorID INT PRIMARY KEY,

Name VARCHAR(50),

Department VARCHAR(50),

Office VARCHAR(50)

);

CREATE TABLE Teaches (

ProfessorID INT,

CourseID INT,

Semester VARCHAR(20),

Year INT,

PRIMARY KEY (ProfessorID, CourseID, Semester, Year),

FOREIGN KEY (ProfessorID) REFERENCES Professor(ProfessorID),

FOREIGN KEY (CourseID) REFERENCES Course(CourseID)

);

CREATE TABLE Enrolls (

StudentID INT,

CourseID INT,

Grade VARCHAR(2),

PRIMARY KEY (StudentID, CourseID),


FOREIGN KEY (StudentID) REFERENCES Student(StudentID),

FOREIGN KEY (CourseID) REFERENCES Course(CourseID)

);

Inserting Sample Data:

INSERT INTO Student VALUES

(1, 'Alice', '123 Main St', '123-456-7890', 'Computer Science', 3.8),

(2, 'Bob', '456 Elm St', '987-654-3210', 'Mathematics', 3.5);

-- ... Insert data for other tables ...

Running Basic Queries

-- Find all courses taught by Professor Smith in the Fall 2023 semester

SELECT CourseName

FROM Course, Teaches, Professor

WHERE Course.CourseID = Teaches.CourseID

AND Teaches.ProfessorID = Professor.ProfessorID

AND Professor.Name = 'Smith'

AND Teaches.Semester = 'Fall'

AND Teaches.Year = 2023;

-- Find the average GPA of students enrolled in the 'Database Systems' course

SELECT AVG(Student.GPA)

FROM Student, Enrolls, Course

WHERE Student.StudentID = Enrolls.StudentID

AND Enrolls.CourseID = Course.CourseID

AND Course.CourseName = 'Database Systems';


Program-2:

unnormalized database schema for a university

CREATE TABLE Students (

StudentID INT PRIMARY KEY,

StudentName VARCHAR(50),

CourseID INT,

CourseName VARCHAR(50),

ProfessorName VARCHAR(50),

ProfessorEmail VARCHAR(50)

);

normalize this schema into three tables

CREATE TABLE Students (

StudentID INT PRIMARY KEY,

StudentName VARCHAR(50)

);

CREATE TABLE Courses (

CourseID INT PRIMARY KEY,

CourseName VARCHAR(50),

ProfessorID INT

);

CREATE TABLE Professors (

ProfessorID INT PRIMARY KEY,

ProfessorName VARCHAR(50),

ProfessorEmail VARCHAR(50)

);

Comparing Query Performance

SELECT *
FROM Students

INNER JOIN Courses ON Students.CourseID = Courses.CourseID

INNER JOIN Professors ON Courses.ProfessorID = Professors.ProfessorID;

Implementation and Performance Measurement

CREATE TABLE Students (

StudentID INT PRIMARY KEY,

StudentName VARCHAR(50),

CourseID INT,

CourseName VARCHAR(50),

ProfessorName VARCHAR(50),

ProfessorEmail VARCHAR(50)

);

You might also like