Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Database for University Management System

Data Base 2 | 341 Team

Members :
Abdelmessih Ashraf Sobhy : 20211169
Esraa Mohamed Mahmoud : 20200728
Mariam Essam Aref : 20200698
Amr Ahmed Farouk : 20200930
Evon Michel Zalzal : 20200906
Introduction:
University Management System starts with the registration of new staff and students. when
the subjects are allocated to the staff the head of the department should enter the detailed
information in the excel sheet. The staff enters the attendance of the students of their
corresponding subjects and marks of the students.

1 - Entity Relationship Diagram ( ERD ) It is a graphical representation that provides a visual


starting point for database design that depicts relationships among people, objects, places,
concepts or events within an information technology system. It helps everyone understand the
foundations of the data/information that is going to be stored within their database.
2- Schema A database schema is the skeleton structure that represents the logical view of the
entire database. It defines how data is organized within a database; this is inclusive of logical
constraints such as, table names, fields, data types, and the relationships between these
entities, primary or foreign keys, etc. A schema does not physically contain the data itself;
instead, it gives information about the shape of data and how it can be related to other tables
or models
Create and Insert

Course Table:

CREATE TABLE Course


(
Course_ID VARCHAR(8) NOT NULL,
Course_name VARCHAR(40) NOT NULL,
Max_Student INT NOT NULL,
Credit_Hours INT NOT NULL,
Price INT NOT NULL,
PRIMARY KEY (Course_ID)
); INSERT ALL

INTO Course (Course_ID,Course_name,Max_Student,Credit_Hours,Price) VALUES


('MRKT160','Marketing',80,3,3500)
INTO Course (Course_ID,Course_name,Max_Student,Credit_Hours,Price) VALUES
('COMP101','Introdution to Computer',80,3,3500)
INTO Course (Course_ID,Course_name,Max_Student,Credit_Hours,Price) VALUES
('MEDI101','Introdution to Media',75,2,1500)
INTO Course (Course_ID,Course_name,Max_Student,Credit_Hours,Price) VALUES
('CIVL101','Introdution to Civil Engineering',65,4,3500)
INTO Course (Course_ID,Course_name,Max_Student,Credit_Hours,Price) VALUES
('CLAW209','Criminal Law',50,4,4500)
SELECT * FROM DUAL;
Faculty Table:

CREATE TABLE Faculty


(
Faculty_Name VARCHAR(20) NOT NULL,
Building_No INT NOT NULL,
MIn_Age INT NOT NULL,
Min_Grade INT NOT NULL,
No_of_course INT NOT NULL,
PRIMARY KEY (Faculty_Name)
);

INSERT ALL

INTO Faculty (Faculty_Name,Building_No,MIn_Age,Min_Grade,No_of_course) VALUES


('Business',03,16,60,48)
INTO Faculty (Faculty_Name,Building_No,MIn_Age,Min_Grade,No_of_course) VALUES
('Mass Communication',05,17,60,50)
INTO Faculty (Faculty_Name,Building_No,MIn_Age,Min_Grade,No_of_course) VALUES
('Engineering',01,18,85,52)
INTO Faculty (Faculty_Name,Building_No,MIn_Age,Min_Grade,No_of_course) VALUES
('Computer Science',04,18,95,52)
INTO Faculty (Faculty_Name,Building_No,MIn_Age,Min_Grade,No_of_course) VALUES
('Law',02,18,70,58)
SELECT * FROM DUAL;
Department Table:

CREATE TABLE Department


(
Dept_ID INT NOT NULL,
Dept_Name VARCHAR(50) NOT NULL,
Max_Student INT NOT NULL,
Supervisor VARCHAR(25) NOT NULL,
Faculty_Name VARCHAR(20) NOT NULL,
PRIMARY KEY (Dept_ID),
FOREIGN KEY (Faculty_Name) REFERENCES Faculty(Faculty_Name)
);

INSERT ALL

INTO Department (Dept_ID,Dept_Name,Max_Student,Supervisor,Faculty_Name) VALUES


(10,'Data Science',150,'Amr','Computer Science')
INTO Department (Dept_ID,Dept_Name,Max_Student,Supervisor,Faculty_Name) VALUES
(20,'Marketing',140,'Abdelmessih','Business')
INTO Department (Dept_ID,Dept_Name,Max_Student,Supervisor,Faculty_Name) VALUES
(30,'Media',150,'Mariam','Mass Communication')
INTO Department (Dept_ID,Dept_Name,Max_Student,Supervisor,Faculty_Name) VALUES
(40,'Architecture',200,'Esraa','Engineering')
INTO Department (Dept_ID,Dept_Name,Max_Student,Supervisor,Faculty_Name) VALUES
(50,'Law',200,'Evon','Law')
SELECT * FROM DUAL;
Student Table:

CREATE TABLE Student


(
StudentID INT NOT NULL,
Age INT NOT NULL,
Date_of_birth DATE NOT NULL,
Phone_Num NUMERIC(11) NOT NULL,
Stu_Name VARCHAR(25) NOT NULL,
Gender VARCHAR(6) NOT NULL,
Faculty_Name VARCHAR(15) NOT NULL,
PRIMARY KEY (StudentID),
FOREIGN KEY (Faculty_Name) REFERENCES Faculty(Faculty_Name)
);

INSERT ALL

INTO Student (StudentID,Age,Date_of_birth,Phone_Num,Stu_Name,Gender,Faculty_Name)


VALUES (2022001,16,8/8/2006,01125152234,'Mohamed Ali','Male','Business')
INTO Student (StudentID,Age,Date_of_birth,Phone_Num,Stu_Name,Gender,Faculty_Name)
VALUES (2022002,17,3/11/2004,01005558822,'Randa el Beheiry','Female','Mass
Communcation')
INTO Student (StudentID,Age,Date_of_birth,Phone_Num,Stu_Name,Gender,Faculty_Name)
VALUES (2021003,17,7/9/2005,01115555992,'Botros Ghaly','Male','Engeneering')
INTO Student (StudentID,Age,Date_of_birth,Phone_Num,Stu_Name,Gender,Faculty_Name)
VALUES (2020007,19,5/5/2003,01227530069,'Mike wazowski','Other','Computer
Science')
INTO Student (StudentID,Age,Date_of_birth,Phone_Num,Stu_Name,Gender,Faculty_Name)
VALUES (2019005,21,7/7/2001,01224567894,'Summer Smith','Female','Law')
SELECT * FROM DUAL;
Doctor Table:

CREATE TABLE Doctor


(
Doctor_ID INT NOT NULL,
Age INT NOT NULL,
Doc_Name VARCHAR(25) NOT NULL,
Phone_Num NUMERIC(11) NOT NULL,
Gender VARCHAR(6) NOT NULL,
Dept_ID INT NOT NULL,
PRIMARY KEY (Doctor_ID),
FOREIGN KEY (Dept_ID) REFERENCES Department(Dept_ID)
);

INSERT ALL

INTO Doctor (Doctor_ID,Age,Doc_Name,Phone_Num,Gender,Dept_ID) VALUES


(1001,45,'Ali El Sayed',01558421520,'Male',10)
INTO Doctor (Doctor_ID,Age,Doc_Name,Phone_Num,Gender,Dept_ID) VALUES
(1002,50,'Shaymaa Asaad',012253005241,'Female',20)
INTO Doctor (Doctor_ID,Age,Doc_Name,Phone_Num,Gender,Dept_ID) VALUES
(1003,39,'Mohsen Momtaz',01006660000,'Male',30)
INTO Doctor (Doctor_ID,Age,Doc_Name,Phone_Num,Gender,Dept_ID) VALUES
(1004,28,'Sandra Medhat',01225556969,'Female',40)
INTO Doctor (Doctor_ID,Age,Doc_Name,Phone_Num,Gender,Dept_ID) VALUES
(1005,60,'Fawaz El Tayer',01000560437,'Male',50)
INTO Doctor (Doctor_ID,Age,Doc_Name,Phone_Num,Gender,Dept_ID) VALUES
(1007,65,'Mohamed El Tayer',01105560437,'Male',50)
SELECT * FROM DUAL;
Studies Table:

CREATE TABLE Studies


(
Course_ID VARCHAR(8) NOT NULL,
StudentID INT NOT NULL,
PRIMARY KEY (Courseq_ID, StudentID),
FOREIGN KEY (Course_ID) REFERENCES Course(Course_ID),
FOREIGN KEY (StudentID) REFERENCES Student(StudentID)
);

INSERT ALL

INTO Studies (Course_ID,StudentID) VALUES ('MRKT160',2022001)


INTO Studies (Course_ID,StudentID) VALUES ('COMP101',2021003)
INTO Studies (Course_ID,StudentID) VALUES ('MEDI101',2022002)
INTO Studies (Course_ID,StudentID) VALUES ('CIVL101',2020007)
INTO Studies (Course_ID,StudentID) VALUES ('CLAW209',2019005)
SELECT * FROM DUAL;
Queries
1- select *

Select *
From Student;

2- Select with condition

SELECT Supervisor
From Department
Where Dept_Name = 'Data Science' or Dept_Name = 'Marketing';

3- Alias

Select STU_NAME As Name


From Student
Where StudentID = 2020007 or StudentID = 2022002;
4- Arithmetic Operator

Select Course_name "Course Name", Course_ID "Course Code" , Price + 500 "Price
After Increase"
From Course
Where Course_ID = 'MRKT160' or Course_ID = 'CLAW209';

5- IN Operator

Select Course_name "Course Name", Course_ID "Course Code", Credit_Hours "Credit


Hours"
From Course
Where Max_Student in (80, 75);

6- LIKE Operator

Select STU_name "Name" , Phone_Num "Phone Number"


From Student
Where Phone_Num Like '_2%';
7 - Comparison Operator

Select Course_name "Course Name", Credit_Hours "Credit Hours" , Price


From Course
Where Credit_Hours <= 3;

8 - Order By

Select Order by:


Select Course_name "Course Name", Credit_Hours "Credit Hours" , Price
From Course
Order By Price DESC;

9 - Equi Join

Select Course_ID || Course_name , Price


Frome Course
Where Credit_Hours = 3;
10 – Left Join

Select Department.Dept_ID "Department ID", Department.Dept_Name "Name",


Doctor.Doc_Name "Doctor Name", Doctor.Dept_ID "Department ID"
From Department
LEFT JOIN Doctor
ON Department.Dept_Id = Doctor.Dept_ID;

11 – Right Join

Select Doctor.Doc_Name "Doctor Name", Doctor.Dept_ID "Department ID",


Department.Dept_ID "Department ID", Department.Dept_Name "Name"
From Doctor
RIGHT JOIN Department
ON Department.Dept_Id = Doctor.Dept_ID;
12 – Full Join

From Doctor
FUll JOIN Department
ON Department.Dept_Id = Doctor.Dept_ID;

13 – Cross Join :

Select Studies.StudentID, Course.Course_name


From Studies
CROSS JOIN Course;
14 – Group Function :

Select Count (*)


From Student
Where Gender = 'Male';

15 – Sub query

Select Course_name 'Name', Price


From Course
Where Price > (
Select Avg(Price)
From Course
);

You might also like