0% found this document useful (0 votes)
21 views4 pages

Univesity Management System Databasee

Uploaded by

Holyy Salsa
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)
21 views4 pages

Univesity Management System Databasee

Uploaded by

Holyy Salsa
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/ 4

UNIVESITY MANAGEMENT SYSTEM

DATABASE PROJECT
Name:Huzaifa Sohail
Id.No: F2021105126

-- Create the database


CREATE DATABASE UniversityManagementSystem;
USE UniversityManagementSystem;

-- Create the Department table


CREATE TABLE Department (
department_id INT PRIMARY KEY,
department_name VARCHAR(50) NOT NULL
);

-- Insert values into the Department table


INSERT INTO Department (department_id, department_name) VALUES
(1, 'Computer Science'),
(2, 'Mathematics'),
(3, 'Physics'),
(4, 'Chemistry'),
(5, 'Biology');

-- Create the Course table


CREATE TABLE Course (
course_id INT PRIMARY KEY,
course_name VARCHAR(50) NOT NULL,
department_id INT,
credits INT,
semester VARCHAR(50),
FOREIGN KEY (department_id) REFERENCES Department(department_id)
);

-- Insert values into the Course table


INSERT INTO Course (course_id, course_name, department_id, credits, semester, location) VALUES
(1, 'Introduction to Programming', 1, 3, 'Fall', 'Building A'),
(2, 'Calculus I', 2, 4, 'Spring', 'Building B'),
(3, 'Mechanics', 3, 3, 'Fall', 'Building C'),
(4, 'Organic Chemistry', 4, 4, 'Spring', 'Building D'),
(5, 'Cell Biology', 5, 3, 'Fall', 'Building E');

-- Create the Student table


CREATE TABLE Student (
student_id INT PRIMARY KEY,
student_name VARCHAR(50) NOT NULL,
department_id INT,
FOREIGN KEY (department_id) REFERENCES Department(department_id)
);
-- Insert values into the Student table
INSERT INTO Student (student_id, student_name, department_id) VALUES
(1, 'John Doe', 1),
(2, 'Jane Smith', 2),
(3, 'Michael Johnson', 3),
(4, 'Emily Davis', 4),
(5, 'Daniel Wilson', 1);
select * from Student
-- Create the Professor table
CREATE TABLE Professor (
professor_id INT PRIMARY KEY,
professor_name VARCHAR(50) NOT NULL,
department_id INT,
FOREIGN KEY (department_id) REFERENCES Department(department_id)
);

-- Insert values into the Professor table


INSERT INTO Professor (professor_id, professor_name, department_id) VALUES
(1, 'Dr. Robert Anderson', 1),
(2, 'Dr. Sarah Wilson', 2),
(3, 'Dr. David Thompson', 3),
(4, 'Dr. Emma Parker', 4),
(5, 'Dr. Andrew White', 1);

-- Create the Enrollment table


CREATE TABLE Enrollment (
enrollment_id INT PRIMARY KEY,
student_id INT,
course_id INT,
FOREIGN KEY (student_id) REFERENCES Student(student_id),
FOREIGN KEY (course_id) REFERENCES Course(course_id)
);

-- Insert values into the Enrollment table


INSERT INTO Enrollment (enrollment_id, student_id, course_id) VALUES
(1, 1, 1),
(2, 2, 2),
(3, 3, 3),
(4, 4, 4),
(5, 5, 5);

-- Create the Grade table


CREATE TABLE Grade (
grade_id INT PRIMARY KEY,
enrollment_id INT,
grade_value VARCHAR(2),
FOREIGN KEY (enrollment_id) REFERENCES Enrollment(enrollment_id)
);

-- Insert values into the Grade table


INSERT INTO Grade (grade_id, enrollment_id, grade_value) VALUES
(1, 1, 'A'),
(2, 2, 'B+'),
(3, 3, 'A-'),
(4, 4, 'B'),
(5, 5, 'A');

-- Alter table to add a column


ALTER TABLE Course
ADD location VARCHAR(50);

-- Drop a column
ALTER TABLE Course
DROP column location;

-- Update records
UPDATE Student
SET department_id = 2
WHERE student_id = 1;

select * from student

-- Delete records
DELETE FROM Grade;

-- Select using operators


SELECT *
FROM Student
WHERE department_id = 1 AND student_id > 10;

-- Select using GROUP BY and aggregate function


SELECT department_id, COUNT(*) AS student_count
FROM Student
GROUP BY department_id;

-- Select using HAVING


SELECT department_id, COUNT(*) AS student_count
FROM Student
GROUP BY department_id
HAVING COUNT(*) > 1;

-- Select using ORDER BY


SELECT *
FROM Student
ORDER BY student_name ASC;

-- Select using JOIN


SELECT Student.student_name, Course.course_name
FROM Student
JOIN Enrollment ON Student.student_id = Enrollment.student_id
JOIN Course ON Enrollment.course_id = Course.course_id;
ERD Diagram:

You might also like