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

University DB

The document contains SQL commands to create tables and insert data for a university student information system database. It defines tables for students, classes, faculty and enrollments, and provides sample data and queries to retrieve information from the tables such as counting students, finding class enrollments, and calculating student GPAs.
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 views13 pages

University DB

The document contains SQL commands to create tables and insert data for a university student information system database. It defines tables for students, classes, faculty and enrollments, and provides sample data and queries to retrieve information from the tables such as counting students, finding class enrollments, and calculating student GPAs.
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/ 13

Using the mySQL client, create the university student information system database with a name

of this format (lastname_university)

CREATE TABLE student(

studID varchar(11),

studLname varchar(50),

studFname varchar(50),

studBdate Date,

studGender varchar(2),
primary key (studID));

CREATE TABLE class(

classCode varchar(15) primary key,

className varchar(45),

classUnit int);

CREATE TABLE faculty(

facNo varchar(8),

facLName varchar(20),

facFName varchar (20),

primary key (facNo));

CREATE TABLE enrollment(

enrollCode varchar(10),

studID varchar(11),

classCode varchar(15),

facNo varchar(8),
grade decimal(2,1),

primary key (enrollCode),

foreign key (studID) references student(studID),

foreign key(classCode) references class(classCode),

foreign key(facNo) references faculty(facNo));

/* Data for Student */

INSERT INTO student

VALUES ('2022-0001A', 'Cruz', 'Matthew', '2001-01-30','M');

INSERT INTO student

VALUES ('2022-0002A', 'Cortez', 'Shamil', '2002-03-24','F');

INSERT INTO student

VALUES ('2022-0003A', 'Montes', 'Elijah', '2002-04-08','M');

INSERT INTO student

VALUES ('2022-0004A', 'Santos', 'Donella', '2002-04-08','F');

INSERT INTO student

VALUES ('2022-0005A', 'Silva', 'Maria', '2002-12-25','F');

INSERT INTO student

VALUES ('2022-0006A', 'Herrera', 'Neizan', '2003-07-31','M');


INSERT INTO student

VALUES ('2022-0007A', 'Blanco', 'Fidela', '2003-09-26','F');

INSERT INTO student

VALUES ('2022-0008A', 'Calvo', 'Simon', '2002-07-07','M');

INSERT INTO student

VALUES ('2022-0009A', 'Espina', 'Stefanu', '2003-07-31','M');

INSERT INTO student

VALUES ('2022-0010A', 'Alonso', 'Elsa', '2003-10-23','F');

INSERT INTO student

VALUES ('2023-0001A', 'Domingo', 'Melisa', '2000-03-01','F');

INSERT INTO student

VALUES ('2023-0002A', 'Vega', 'Usher', '2001-03-24','M');

INSERT INTO student

VALUES ('2023-0003A', 'Garcia', 'Mechiah', '2002-04-19','F');

INSERT INTO student

VALUES ('2023-0004A', 'Cruz', 'Clemente', '2002-12-25','M');

INSERT INTO student

VALUES ('2023-0005A', 'Cartagena', 'Beverly', '2003-05-25','F');


INSERT INTO student

VALUES ('2023-0006A', 'Martinez', 'Mariam', '2003-11-30','F');

INSERT INTO student

VALUES ('2023-0007A', 'Salvador', 'Trini', '2003-03-15','M');

INSERT INTO student

VALUES ('2023-0008A', 'Calayco','April Dawn', '2003-12-31','F');

INSERT INTO student

VALUES ('2023-0009A', 'Chaves', 'Antonio', '2002-09-11','M');

INSERT INTO student

VALUES ('2023-0010A', 'Serrano', 'Felipe', '2002-04-20','M');

/* Data for Class */

INSERT INTO class

VALUES ('ICT 102', 'Introduction to Computing', '3');

INSERT INTO class

VALUES ('CS 1', 'Programming Logic Formulation', '3');

INSERT INTO class

VALUES ('ICT 103', 'Fundamentals of Programming', '3');


INSERT INTO class

VALUES ('IT 102', 'Digital Circuits', '3');

INSERT INTO class

VALUES ('ICT 104', 'Intermediate Programming', '3');

INSERT INTO class

VALUES ('ICT 109', 'Information Management', '3');

INSERT INTO class

VALUES ('ICT 107', 'Data Structures and Algorithm', '3');

INSERT INTO class

VALUES ('ICT 113', 'Networking', '3');

INSERT INTO class

VALUES ('ICT 138', 'Systems Analysis and Design', '3');

INSERT INTO class

VALUES ('IT 104', 'Platform Technologies', '3');

/*Faculty Data */

INSERT INTO faculty

VALUES ('02-001', 'Herrera', 'Luis');


INSERT INTO faculty

VALUES ('02-002', 'Amador', 'Rico');

INSERT INTO faculty

VALUES ('02-003', 'Avila', 'Aseneth');

INSERT INTO faculty

VALUES ('02-004', 'Vega', 'Andrew');

INSERT INTO faculty

VALUES ('02-005', 'Valiente', 'Ma.Josie');

/*Enrollment Data */

INSERT INTO enrollment

VALUES ('2022-0001', '2022-0001A', 'CS 1', '02-002', 1.2),

('2022-0002', '2022-0001A', 'ICT 102', '02-001', 1.5),

('2022-0003', '2022-0001A', 'ICT 103', '02-002', 1.8),

('2022-0004', '2022-0001A', 'ICT 104', '02-003', 2.0),

('2022-0005', '2022-0001A', 'ICT 107', '02-005', 1.5);

INSERT INTO enrollment

VALUES ('2022-0006', '2022-0002A', 'CS 1', '02-002', 1.8),

('2022-0007', '2022-0002A', 'ICT 102', '02-001', 2.0),

('2022-0008', '2022-0002A', 'ICT 103', '02-002', 1.9),

('2022-0009', '2022-0002A', 'ICT 104', '02-003', 2.2),

('2022-0010', '2022-0002A', 'ICT 107', '02-005', 1.7);


INSERT INTO enrollment

VALUES ('2022-0011', '2022-0003A', 'CS 1', '02-002', 1.6),

('2022-0012', '2022-0003A', 'ICT 102', '02-001', 1.8),

('2022-0013', '2022-0003A', 'ICT 103', '02-002', 1.9),

('2022-0014', '2022-0003A', 'ICT 104', '02-003', 2.0),

('2022-0015', '2022-0003A', 'ICT 107', '02-005', 1.7);

INSERT INTO enrollment


VALUES ('2022-0016', '2022-0004A', 'CS 1', '02-002', 1.8),

('2022-0017', '2022-0004A', 'ICT 102', '02-001', 2.0),

('2022-0018', '2022-0004A', 'ICT 103', '02-002', 2.0),

('2022-0019', '2022-0004A', 'ICT 104', '02-003', 1.9),

('2022-0020', '2022-0004A', 'ICT 107', '02-005', 2.0);

INSERT INTO enrollment

VALUES ('2022-0021', '2022-0005A', 'CS 1', '02-002', 1.2),

('2022-0022', '2022-0005A', 'ICT 102', '02-001', 1.4),

('2022-0023', '2022-0005A', 'ICT 103', '02-002', 1.1),

('2022-0024', '2022-0005A', 'ICT 104', '02-003', 1.5),

('2022-0025', '2022-0005A', 'ICT 107', '02-005', 1.6);

INSERT INTO enrollment

VALUES ('2022-0026', '2022-0006A', 'CS 1', '02-002', 1.6),

('2022-0027', '2022-0006A', 'ICT 102', '02-001', 1.9),

('2022-0028', '2022-0006A', 'ICT 103', '02-002', 2.0),

('2022-0029', '2022-0006A', 'ICT 104', '02-003', 2.2),


('2022-0030', '2022-0006A', 'ICT 107', '02-005', 1.9);

INSERT INTO enrollment

VALUES ('2022-0031', '2022-0008A', 'CS 1', '02-002', 1.6),

('2022-0032', '2022-0008A', 'ICT 102', '02-001', 1.9),

('2022-0033', '2022-0008A', 'ICT 103', '02-002', 2.0),

('2022-0034', '2022-0008A', 'ICT 104', '02-003', 2.2),

('2022-0035', '2022-0008A', 'ICT 107', '02-005', 1.9);

INSERT INTO enrollment

VALUES ('2023-0001', '2023-0001A', 'ICT 109', '02-004', 1.6),

('2023-0002', '2023-0001A', 'ICT 113', '02-001', 1.9),

('2023-0003', '2023-0001A', 'ICT 138', '02-004', 2.0),

('2023-0004', '2023-0001A', 'ICT 102', '02-003', 2.2),

('2023-0005', '2023-0001A', 'ICT 104', '02-002', 1.9);

INSERT INTO enrollment

VALUES ('2023-0006', '2023-0002A', 'ICT 109', '02-004', 1.8),

('2023-0007', '2023-0002A', 'ICT 113', '02-001', 1.5),

('2023-0008', '2023-0002A', 'ICT 138', '02-004', 2.2),

('2023-0009', '2023-0002A', 'ICT 102', '02-003', 2.0),

('2023-0010', '2023-0002A', 'ICT 104', '02-002', 1.5);

INSERT INTO enrollment

VALUES ('2023-0011', '2023-0003A', 'ICT 109', '02-004', 1.8),

('2023-0012', '2023-0003A', 'ICT 113', '02-001', 1.5),


('2023-0013', '2023-0003A', 'ICT 138', '02-004', 2.2),

('2023-0014', '2023-0003A', 'ICT 104', '02-002', 1.5);

INSERT INTO enrollment

VALUES ('2023-0015', '2023-0005A', 'ICT 109', '02-004', 2.0),

('2023-0016', '2023-0005A', 'ICT 113', '02-001', 1.9),

('2023-0017', '2023-0005A', 'ICT 138', '02-004', 2.0),

('2023-0018', '2023-0005A', 'ICT 102', '02-003', 1.8),

('2023-0019', '2023-0005A', 'ICT 104', '02-002', 1.5);

INSERT INTO enrollment

VALUES ('2023-0020', '2023-0006A', 'ICT 109', '02-004', 1.4),

('2023-0021', '2023-0006A', 'ICT 113', '02-001', 1.8),

('2023-0022', '2023-0006A', 'ICT 138', '02-004', 1.6),

('2023-0023', '2023-0006A', 'ICT 104', '02-002', 1.7);

INSERT INTO enrollment

VALUES ('2023-0024', '2023-0009A', 'ICT 109', '02-004', 1.8),

('2023-0025', '2023-0009A', 'ICT 113', '02-001', 2.0),

('2023-0026', '2023-0009A', 'ICT 138', '02-004', 2.0),

('2023-0027', '2023-0009A', 'ICT 102', '02-003', 2.1),

('2023-0028', '2023-0009A', 'ICT 104', '02-002', 2.0);

commit;
/*Sample SQL commands */

/*Count the number of student */

SELECT COUNT(studID) AS NumOfStudent

FROM student;

/* Find the number of students who have enrollment record */

SELECT COUNT(DISTINCT studID) AS NumEnrolled

FROM enrollment;

/*Find the number of students enrolled in ICT 109 */

SELECT COUNT(studID) NumEnrolledICT109

FROM enrollment

WHERE classCode='ICT 109';

/* Find the number of students per class */

SELECT classCode, COUNT(studID)

FROM enrollment

GROUP BY classCode;

/*Find the class with number of students greater than 10 */

SELECT classCode, COUNT(studID) ClassNumStud

FROM enrollment

GROUP BY classCode

HAVING ClassNumStud>10;

/*Find the grade point average of student with ID Num 2022-0001A */


/*Note: use AVG function e.g. AVG(grade) */

SELECT student.studID, studLname, studFname, AVG(grade)

FROM enrollment, student

WHERE enrollment.studID='2022-0001A' AND student.studID=enrollment.studID;

SELECT S.studID, studLname, studFname, AVG(grade)

FROM enrollment E, student S

WHERE E.studID='2022-0001A' AND S.studID=E.studID;

/*Find the GPA of all the students */

SELECT S.studID, studLname, studFname, AVG(grade) GPA

FROM enrollment AS E, student AS S

WHERE E.studID=S.studID

GROUP BY studID;

/*Find the GPA of all the students with latin honors */

SELECT S.studID, studLname, studFname, AVG(grade) GPA

FROM enrollment AS E, student AS S

WHERE E.studID=S.studID

GROUP BY studID

HAVING GPA BETWEEN 1.0 AND 1.5;

/*Find the GPA of all the students with latin honors */

SELECT S.studID, studLname, studFname, AVG(grade) GPA

FROM enrollment AS E, student AS S


WHERE E.studID=S.studID

GROUP BY studID

HAVING GPA>=1.0 AND GPA<=1.5;

/*Find the name of the students with GPA equal to 1.92 */

SELECT S.studID, studLname, studFname, AVG(grade) GPA

FROM enrollment AS E, student AS S

WHERE E.studID=S.studID
GROUP BY studID

HAVING GPA=1.92;

/*Find the name of students with GPA between 1.0 and 1.5 */

SELECT S.studID, studLname, studFname, AVG(grade) GPA

FROM enrollment AS E, student AS S

WHERE E.studID=S.studID

GROUP BY studID

HAVING GPA BETWEEN 1.0 and 1.5;

/*Find the name of students with GPA of 1.3, 1.5, 1.8, 1.9 */

SELECT S.studID, studLname, studFname, AVG(grade) GPA

FROM enrollment AS E, student AS S

WHERE E.studID=S.studID

GROUP BY studID

HAVING GPA IN (1.3, 1.5, 1.8, 1.9);

/*Find the highest and the lowest grade based on


ISAT U grading system */

SELECT MAX(grade) lowestGrade, MIN(grade) HighestGrade

FROM enrollment;

/*Find the name of student

with highest grade */

SELECT studLname, studFname, grade

FROM student S, enrollment E


WHERE S.studID=E.studID AND

grade=(SELECT MIN(grade) FROM enrollment);

You might also like