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

TermWorkDBMS

The document outlines a term work project for a Database Management System course at Dharmsinh Desai University. It includes the creation of three tables (Suppliers, Parts, Catalogue) in MySQL, insertion of records, and various SQL queries to retrieve and manipulate data. Additionally, it presents procedures and functions for calculating costs and retrieving supplier information based on part color.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

TermWorkDBMS

The document outlines a term work project for a Database Management System course at Dharmsinh Desai University. It includes the creation of three tables (Suppliers, Parts, Catalogue) in MySQL, insertion of records, and various SQL queries to retrieve and manipulate data. Additionally, it presents procedures and functions for calculating costs and retrieving supplier information based on part color.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Database Management System 1

Dharmsinh Desai University


MCA Department

Semester -I
Termwork of
Database Management System
Student Name: Harsh Jayeshbhai Chandarana
Roll No: MCA021

Submitted To:
Purvi Jardos:

Creating Table

MCA021
Database Management System 2

Perform the following using MySQL Create following tables choose


appropriate datatype. And insert appropriate records according to
your choice.
Suppliers (Sid, S_name, Address) // sid is primary key
Parts (Pid, P_name, Colour) // pid is primary key
Catalogue (Sid, Pid, Cost) // sid and pid is foreignkey and
primarykey(sid,pid)

Table 1 : Suppliers

CREATE TABLE Suppliers (


Sid INT PRIMARY KEY,
S_name VARCHAR(50),
Address VARCHAR(100)
);

Table 2 : Parts

CREATE TABLE Parts (


Pid INT PRIMARY KEY,
P_name VARCHAR(50),
Colour VARCHAR(20)
);

Table 3 : Catalogue

CREATE TABLE Catalogue (


Sid INT,
Pid INT,
Cost DECIMAL(10, 2),
PRIMARY KEY (Sid, Pid),
FOREIGN KEY (Sid) REFERENCES Suppliers(Sid),
FOREIGN KEY (Pid) REFERENCES Parts(Pid)
);

Inserting Records

MCA021
Database Management System 3

Table 1:

INSERT INTO Suppliers (Sid, S_name, Address) VALUES


(1, 'ABC Corp', '123 Market St'),
(2, 'XYZ Ltd', '456 Elm St'),
(3, 'Global Supplies', '789 Maple Ave'),
(4, 'Tech Solutions', '101 Oak St'),
(5, 'Mega Suppliers', '202 Pine St'),
(6, 'QuickShip', ''),
(7, 'ValueMart', ''),
(8, 'Premium Parts', '505 Spruce St'),
(9, 'Discount Supplies', '606 Fir St'),
(10, 'SuperStock', '707 Redwood St');
(11, 'Supermarket', '');
(12, ‘Harsh’);
(13, ‘Rakesh’, ‘Mumbai’);

Table 2:

INSERT INTO Parts (Pid, P_name, Colour) VALUES


(101, 'Widget', 'Red'),
(102, 'Gizmo', 'Blue'),
(103, 'Doohickey', 'Green'),
(104, 'Thingamajig', 'Yellow'),
(105, 'Contraption', 'Purple'),
(106, 'Gadget', 'Orange'),
(107, 'Apparatus', 'Pink'),
(108, 'Device', 'Brown'),
(109, 'Mechanism', 'Black'),
(110, 'Instrument', 'White');
(111, 'USB', 'Red');
(112, ‘Bolt’,‘Red’);

MCA021
Database Management System 4

Table 3:

INSERT INTO Catalogue (Sid, Pid, Cost) VALUES


(1, 101, 10.50),
(1, 102, 12.75),
(2, 103, 8.00),
(2, 104, 11.25),
(3, 105, 9.50),
(3, 106, 14.00),
(4, 107, 7.75),
(4, 108, 10.00),
(5, 109, 13.25),
(5, 110, 15.00);
(11, 111, 15.32);
(12, 112, 500.00);

Output’s Of Tables

Select * from suppliers;

Sid S_name Address


1 ABC Corp 123 Market St
2 XYZ LTD 456 ELm St
3 Global Supplies 789 Maple Ave
4 Teck Solutions 101 Oak St
5 Mega Suppliers 202 Pine St
6 Quick Ship 303 Birch St
7 Value Mart 404 Cedar St
8 Premuim Marts 505 Spruce St
9 Discount Supplies 606 Fir St
10 Super Stock 707 Redwood St
11 Super Market
12 Harsh NULL
13 Rakesh Mumbai

Select * from Parts;

MCA021
Database Management System 5

Pid P_name Colour


101 Widget Red
102 Gizmo Blue
103 Doohickey Green
104 Thingamajig Yellow
105 Contraption Purple
106 Gadget Orange
107 Apparatus Pink
108 Device Brown
109 Mechanism Black
110 Instrument White
111 USB Red
112 Bolt Red

select * from catalogue;

Sid Pid Cost


1 101 10.50
1 102 12.75
2 103 8.00
2 104 11.25
3 105 9.50
3 106 14.00
4 107 7.75
4 108 10.00
5 109 13.25
5 110 15.00
11 111 15.32
13 112 500.00

MCA021
Database Management System 6

Question 1

Display all the suppliers whose name start with ‘S’

Querie

SELECT * FROM Suppliers WHERE S_name LIKE 'S%';

Output

Sid S_name Address


10 Superstock 707 Redwood St
11 Supermarket

MCA021
Database Management System 7

Question 2

Display all the suppliers detail whose address is null

Querie

SELECT * FROM Suppliers WHERE Address IS NULL;

Output

Sid S_name Address


12 Harsh NULL

MCA021
Database Management System 8

Question 3

Display the supplier name who is supplies the red color


parts

Querie

SELECT Suppliers.S_name
FROM Suppliers
JOIN Catalogue ON Suppliers.Sid = Catalogue.Sid
JOIN Parts ON Catalogue.Pid = Parts.Pid
WHERE Parts.Colour = 'Red';

Output

S_name
ABC Corp
Super Market

MCA021
Database Management System 9

Question 4

Display the partname who has maximum cost.

Querie

SELECT P_name
FROM Parts
JOIN Catalogue ON Parts.Pid = Catalogue.Pid
ORDER BY Catalogue.Cost DESC
LIMIT 1;

Output

P_name
USB

Question 5
MCA021
Database Management System 10

Display name and total cost of part which have total cost
greater than 10 Rs

Querie

SELECT Parts.P_name, SUM(Catalogue.Cost) AS Total_Cost


FROM Parts
JOIN Catalogue ON Parts.Pid = Catalogue.Pid
GROUP BY Parts.P_name
HAVING Total_Cost > 10;

Output

P_name Total_Cost
Widget 10.50
Gizmo 12.75
Thingamajig 11.25
Gadget 14.00
Mechanism 13.25
Instrument 15.00
USB 15.32

MCA021
Database Management System 11

Question 6

Display all the part name which is supplied by supplier


“Harsh”.

Querie

SELECT Parts.P_name
FROM Parts
JOIN Catalogue ON Parts.Pid = Catalogue.Pid
JOIN Suppliers ON Catalogue.Sid = Suppliers.Sid
WHERE Suppliers.S_name = ‘Rakesh';

Output

P_name
Bolt

MCA021
Database Management System 12

Question 7

Display the pid whose total cost is greater than 15.

Querie

SELECT Pid

FROM Catalogue

GROUP BY Pid

HAVING SUM(Cost) > 15;

Output

Pid
111

MCA021
Database Management System 13

Question 8

Update the cost(add 200 in existing cost) which is supplied


by sid = s1;

Querie

UPDATE Catalogue SET Cost = Cost + 20 WHERE Sid = '1';

Output

select Sid,Pid,Cost from catalogue where Sid=1;

Sid Pid Cost


1 101 30.50
1 102 32.75

Question 9

MCA021
Database Management System 14

Display the name and total cost supplied by each supplier.

Querie

SELECT S_name, SUM(Cost) AS TotalCost

FROM Suppliers

JOIN Catalogue ON Suppliers.Sid = Catalogue.Sid

GROUP BY S_name;

Output

S_name Total_cost
ABC Corp 63.25
XYZ LTD 19.25
Global Supplies 23.50
Tech Solutions 17.75
Mega Suppliers 28.25
Super Market 15.32

Question 10

MCA021
Database Management System 15

Create procedure which pass the name of partname as


arguments and find out the total cost of that part and store
in OUT varibable called totalcost.

Querie

DELIMITER $$

CREATE PROCEDURE GetTotalCost(IN part_name VARCHAR(100), OUT


total_cost DECIMAL(10, 2))

BEGIN

SELECT SUM(Cost)

INTO total_cost

FROM Catalogue

JOIN Parts ON Catalogue.Pid = Parts.Pid

WHERE P_name = part_name;

END $$

DELIMITER ;

MCA021
Database Management System 16

Output

CALLGetTotalCost('Widget',@totalcost);

SELECT @totalCost AS Total_cost;

Total_cost
30.50

Question 11

Create a function which pass colour of part as argument and


display the name of supplier who supplies that given color.

Querie
MCA021
Database Management System 17

DELIMITER $$

CREATE FUNCTION GetSuppliersByColor(color VARCHAR(50))

RETURNS VARCHAR(255)

DETERMINISTIC

READS SQL DATA

BEGIN

DECLARE supplier_list VARCHAR(255);

SELECT GROUP_CONCAT(S_name)

INTO supplier_list

FROM Suppliers

JOIN Catalogue ON Suppliers.Sid = Catalogue.Sid

JOIN Parts ON Catalogue.Pid = Parts.Pid

WHERE Colour = color;

RETURN supplier_list;

END $$

DELIMITER ;

Output

MCA021
Database Management System 18

SELECT GetSuppliersByColor('Red');

Names
ABC Corp, Super Market, Rakesh

MCA021

You might also like