0% found this document useful (0 votes)
4 views

DBMS_practical

Uploaded by

A.k Unity world
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

DBMS_practical

Uploaded by

A.k Unity world
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Skill Based Mini Project Report

Submitted for the partial fulfilment of the degree of

Bachelor of Technology
In
Artificial Intelligence and Machine Learning
Submitted By

ADITYA KUMAR SINGH


0901AM231004
UNDER THE SUPERVISION AND GUIDANCE OF

Mr. Ramnaresh Sharma


(Assistant Professor)
Dr. Hardev Singh Pal
(Assistant Professor)

Centre for Artificial Intelligence

Session 2024-25
DECLARATION BY THE CANDIDATE

We hereby declare that the work entitled “Schema for College Database” is our work,
conducted under the supervision of Mr. Ramnaresh Sharma (Assistant Professor) & Dr.
Hardev Singh Pal (Assistant Professor), during the session Aug-Dec 2024. The report
submitted by us is a record of bonafide work carried out by me.

We further declare that the work reported in this report has not been submitted and will not be
submitted, either in part or in full, for the award of any other degree or diploma in this institute
or any other institute or university.

--------------------------------

Aditya Kumar Singh (0901AM231004)

Date: 19.11.2024
Place: Gwalior

This is to certify that the above statement made by the candidates is correct to the best of our
knowledge and belief.
ACKNOWLEDGEMENT
We would like to express our greatest appreciation to all the individuals who have helped and
supported us throughout this report. We are thankful to the whole Centre for Artificial
Intelligence for their ongoing support during the experiments, from initial advice and provision
of contact in the first stages through ongoing advice and encouragement, which led to the final
report.

A special acknowledgement goes to our colleagues who help us in completing the file and by
exchanging interesting ideas to deal with problems and sharing the experience.

We wish to thank the faculty and supporting staff for their undivided support and interest which
inspired us and encouraged us to go my own way without whom we would be unable to
complete my project.

In the end, We want to thank our friends who displayed appreciation for our work and
motivated us to continue our work.

Aditya Kumar Singh


Consider the schema for College Database: STUDENT (USN, SName, Address,
Phone, Gender) SEMSEC (SSID, Sem, Sec) CLASS (USN, SSID) COURSE
(Subcode, Title, Sem, Credits) IAMARKS (USN, Subcode, SSID, Test1, Test2,
Test3, FinalIA)
Write SQL queries to:
1. List all the student details studying in the fourth semester ‘C’ section.
2. Compute the total number of male and female students in each semester and in each
section.
3. Create a view of Test1 marks of student USN ‘1BI15CS101’ in all Courses.
4. Calculate the FinalIA (average of best two test marks) and update the corresponding
table for all students.
5. Categorize students based on the following criterion:
If FinalIA = 17 to 20 then CAT = ‘Outstanding’
If FinalIA = 12 to 16 then CAT = ‘Average’
If FinalIA< 12 then CAT = ‘Weak’
Give these details only for 8th semester A, B, and C section students.

Defining Keywords:
SSID: Unique identifier for Semester Section (Primary Key)
Sem: Semester number
Sec: Section
USN: Unique Student Number
SSID: Semester Section Identifier
Subcode: Subject code
Title: Course title/name
Sem: Semester in which the course is offered
Credits: Number of credits for the course
Test1: Marks scored in the first internal assessment test
Test2: Marks scored in the second internal assessment test
Test3: Marks scored in the third internal assessment test
FinalIA: Final internal assessment marks, often calculated as an aggregate of
Test1, Test2, and Test3.
Creating Quieries
STEP 1:
Creating the table for all the Queries:

1. Creating the STUDENT table.


CREATE TABLE STUDENT (
USN VARCHAR(10) PRIMARY KEY,
SName VARCHAR(50) NOT NULL,
Address VARCHAR(100),
Phone VARCHAR(15),
Gender CHAR(1) CHECK (Gender IN ('M', 'F'))
);

2. Creating the SEMSEC table.


CREATE TABLE SEMSEC (
SSID INT PRIMARY KEY,
Sem INT CHECK (Sem BETWEEN 1 AND 8),
Sec CHAR(1) CHECK (Sec IN ('A', 'B', 'C', 'D'))
);

3. Creating the CLASS table.


CREATE TABLE CLASS (
USN VARCHAR(10),
SSID INT,
PRIMARY KEY (USN, SSID),
FOREIGN KEY (USN) REFERENCES STUDENT(USN),
FOREIGN KEY (SSID) REFERENCES SEMSEC(SSID)
);

4. Creating the COURSE table.


CREATE TABLE COURSE (
Subcode VARCHAR(10) PRIMARY KEY,
Title VARCHAR(100) NOT NULL,
Sem INT CHECK (Sem BETWEEN 1 AND 8),
Credits INT CHECK (Credits > 0)
);

5. Creating the IAMARKS table.


CREATE TABLE IAMARKS (
USN VARCHAR(10),
Subcode VARCHAR(10),
SSID INT,
Test1 INT CHECK (Test1 BETWEEN 0 AND 20),
Test2 INT CHECK (Test2 BETWEEN 0 AND 20),
Test3 INT CHECK (Test3 BETWEEN 0 AND 20),
FinalIA DECIMAL(5, 2),
PRIMARY KEY (USN, Subcode, SSID),
FOREIGN KEY (USN) REFERENCES STUDENT(USN),
FOREIGN KEY (Subcode) REFERENCES COURSE(Subcode),
FOREIGN KEY (SSID) REFERENCES SEMSEC(SSID)
);

STEP 2:
Inserting data into the Tables:

1. Insert data into the STUDENT table.


INSERT INTO STUDENT (USN, SName, Address, Phone, Gender) VALUES
('0901AM231001', 'ADITYA KUMAR', 'BHOPAL', '9876543210', 'M'),
('0901AM231002', 'KAMALA HARRIS', 'MUMBAI', '8765432109', 'F'),
('0901AM231003', 'ELON MUSK', 'NEW YORK', '7654321098', 'M'),
('0901AM231004', 'NARENDRA MODI', 'DELHI', '6543210987', 'F');
2. Insert data into the SEMSEC table.
INSERT INTO SEMSEC (SSID, Sem, Sec) VALUES
(1, 4, 'C'),
(2, 8, 'A'),
(3, 8, 'B'),
(4, 8, 'C');

3. Insert data into the CLASS table.


INSERT INTO CLASS (USN, SSID) VALUES
('0901AM231001', 1),
('0901AM231002', 2),
('0901AM231003', 3),
('0901AM231004', 4);
4. Insert data into the COURSE table.
INSERT INTO COURSE (Subcode, Title, Sem, Credits) VALUES
('CS401', 'Database Systems', 4, 4),
('CS402', 'Operating Systems', 4, 4),
('CS801', 'Machine Learning', 8, 4),
('CS802', 'Data Science', 8, 4);

5. Insert data into the IAMARKS table.


INSERT INTO IAMARKS (USN, Subcode, SSID, Test1, Test2, Test3, FinalIA) VALUES
('0901AM231001', 'CS401', 1, 15, 18, 17, NULL),
('0901AM231001', 'CS402', 1, 14, 15, 16, NULL),
('0901AM231002', 'CS801', 2, 18, 19, 17, NULL),
('0901AM231003', 'CS801', 3, 12, 14, 15, NULL),
('0901AM231004', 'CS802', 4, 16, 18, 14, NULL);
STEP 3:
1. List all the student details studying in the fourth semester ‘C’ section.
SELECT S.*
FROM STUDENT S
JOIN CLASS C ON S.USN = C.USN
JOIN SEMSEC SS ON C.SSID = SS.SSID
WHERE SS.Sem = 4 AND SS.Sec = 'C';

2. Compute the total number of male and female students in each semester
and in each section.
SELECT SS.Sem, SS.Sec, S.Gender, COUNT(*) AS TotalCount
FROM STUDENT S
JOIN CLASS C ON S.USN = C.USN
JOIN SEMSEC SS ON C.SSID = SS.SSID
GROUP BY SS.Sem, SS.Sec, S.Gender
ORDER BY SS.Sem, SS.Sec, S.Gender;
3. Create a view of Test1 marks of student USN ‘0901AM231004’ in all
Courses.
CREATE VIEW Test1MarksView AS
SELECT I.Subcode, C.Title, I.Test1
FROM IAMARKS I
JOIN COURSE C ON I.Subcode = C.Subcode
WHERE I.USN = '0901AM231004';

4. Calculate the FinalIA (average of best two test marks) and update the
corresponding table for all students.
UPDATE IAMARKS
SET FinalIA = (
CASE
WHEN Test1 >= Test2 AND Test1 >= Test3 THEN Test1
WHEN Test2 >= Test1 AND Test2 >= Test3 THEN Test2
ELSE Test3
END +
CASE
WHEN (Test1 <= Test2 AND Test1 >= Test3) OR (Test1 >= Test2 AND Test1 <=
Test3) THEN Test1
WHEN (Test2 <= Test1 AND Test2 >= Test3) OR (Test2 >= Test1 AND Test2 <=
Test3) THEN Test2
ELSE Test3
END
) / 2;
5. Categorize students based on the following criterion:
If FinalIA = 17 to 20 then CAT = ‘Outstanding’
If FinalIA = 12 to 16 then CAT = ‘Average’
If FinalIA< 12 then CAT = ‘Weak’
Give these details only for 8th semester A, B, and C section students.

SELECT S.USN, S.SName, SS.Sem, SS.Sec, I.FinalIA,


CASE
WHEN I.FinalIA BETWEEN 17 AND 20 THEN 'Outstanding'
WHEN I.FinalIA BETWEEN 12 AND 16 THEN 'Average'
WHEN I.FinalIA < 12 THEN 'Weak'
END AS CAT
FROM STUDENT S
JOIN CLASS C ON S.USN = C.USN
JOIN SEMSEC SS ON C.SSID = SS.SSID
JOIN IAMARKS I ON S.USN = I.USN
WHERE SS.Sem = 8 AND SS.Sec IN ('A', 'B', 'C');

You might also like