0% found this document useful (0 votes)
22 views21 pages

DBMS Report Dibya Deep Acharya

Uploaded by

Ddapher 69
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)
22 views21 pages

DBMS Report Dibya Deep Acharya

Uploaded by

Ddapher 69
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/ 21

Project Report for

“DBMS”

Submitted by:
Dibya Deep Acharya
TU Registration no: 7-2-22-184-2019

Submitted to:
Dhadi Ram Ghimire

Bachelor of Business Administration

Tribhuvan University
Patan Multiple Campus
Year: 2019

1
Table of Contents
Acknowledgement…………………………………………………………………………………………………………………….. 2
Showing all the available databases in MySQL................................................................................3
SELECTing a database in MySQL......................................................................................................3
Showing all tables belonging to a Database....................................................................................3
DDL CREATE Command to create tables in MySQL..........................................................................4
DDL ALTER Command to Add CONSTRAINT FOREIGN KEY...............................................................4
DDL ALTER Command to Add, Delete and modify Column...............................................................4
DDL ALTER Command to SET DEFAULT VALUES...............................................................................5
MySQL CHECK CONSTRAINT...........................................................................................................5
Displaying the structure of Tables using DESC Commands...............................................................5
DML Command INSERT to INSERT data into tables..........................................................................5
Inserting multiple rows at the same time........................................................................................6
Selecting all the data from the table at once...................................................................................6
SELECT Query Example 1 (Supplier, parts, supplies)........................................................................7
SELECT Query Example 2 (Employee, Company, Works, Supervisor)..............................................10
Practical Examples of all the Sql syntax.……………………………………………………………………………….13

2
Acknowledgement

I would like to express my sincerest gratitude to Mr. Dhadi Ram Ghimire for
allowing me to have this opportunity to finish such a wonderful project report
on Sql and I would like to thank him for his guidance on all the things he taught
me on Sql, Databases, Servers, and Database management system as a whole.
His suggestions and guidance have served a major role in finishing this project.
This research boarded my knowledge in the study of DBMS and has served as a
great tool in refining my Sql skills not just theoretically but practically as well.

3
Showing all the available databases in MySQL

mysql> show databases;

SELECTing a database in MySQL


mysql> use bba;

Database changed

Showing all tables belonging to a Database


mysql> show tables;

4
DDL CREATE Command to create tables in MySQL
Supplier (supplier-id , supplier-name, city)
Supplies (supplier-id, part-id, quantity)
Parts (part-id, par-name, color, weight)
mysql> create table supplier(sid int NOT NULL primary key,sname varchar(20),city
varchar(25));

Query OK, 0 rows affected (0.08 sec)

mysql> create table parts(pid int NOT NULL Primary key,pname varchar(20),color
varchar(10),wt int);

Query OK, 0 rows affected (0.05 sec)

mysql> create table supplies(pid int,sid int,quantity int);

Query OK, 0 rows affected (0.06 sec)

DDL ALTER Command to Add CONSTRAINT FOREIGN KEY


mysql> alter table supplies add CONSTRAINT fk1 FOREIGN KEY(pid) references parts(pid)
ON DELETE CASCASE;

Query OK, 0 rows affected (0.15 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table supplies add CONSTRAINT fk2 FOREIGN KEY(sid) references
supplier(sid) on DELETE CASCADE;

Query OK, 0 rows affected (0.20 sec)

Records: 0 Duplicates: 0 Warnings: 0

DDL ALTER Command to Add, Delete and modify Column


mysql> alter table supplies add column date timestamp;

Query OK, 0 rows affected (0.04 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table supplies rename column date to dop;

Query OK, 0 rows affected (0.04 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table supplies drop column dop;

Query OK, 0 rows affected (0.13 sec)

Records: 0 Duplicates: 0 Warnings: 0

5
DDL ALTER Command to SET DEFAULT VALUES
mysql> alter table supplies alter column quantity SET DEFAULT 1;

Query OK, 0 rows affected (0.02 sec)

Records: 0 Duplicates: 0 Warnings: 0

MySQL CHECK CONSTRAINT


mysql> alter table supplies add constraint ch CHECK(quantity>0);

Query OK, 0 rows affected (0.22 sec)

Records: 0 Duplicates: 0 Warnings: 0

Displaying the structure of Tables using DESC Commands

DML Command INSERT to INSERT data into tables


mysql> INSERT into parts(pid, pname, color, wt) VALUES (1,"mouse","black",50);

6
Query OK, 1 row affected (0.03 sec)

mysql> INSERT into parts(pid,pname,color,wt) VALUES (2,"joystick","black",100);

Query OK, 1 rows affected (0.01 sec)

Records: 2 Duplicates: 0 Warnings: 0

Inserting multiple rows at the same time


mysql> INSERT into parts(pid,pname,color,wt) VALUES (4,"HDMI","black",10),
(6,"keyboard","black",130);

Query OK, 2 rows affected (0.01 sec)

Records: 2 Duplicates: 0 Warnings: 0

mysql> INSERT into parts(pid,pname,color,wt) VALUES (5,"Monitor","black",10),


(7,"RAM","black",130);

Query OK, 2 rows affected (0.01 sec)

Records: 2 Duplicates: 0 Warnings: 0

mysql> INSERT into supplier(sid,sname,city) VALUES(2,"ABC","KTM"),(3,"Shree","LTP");

Query OK, 2 rows affected (0.02 sec)

Records: 2 Duplicates: 0 Warnings: 0

Selecting all the data from the table at once

7
SELECT Query Example 1 (Supplier, parts, supplies)

(a) Find the name of all suppliers located in city “KTM”.


SELECT sname FROM supplier WHERE city="KTM";

(b) Find the name of all parts supplied “ABC” company.


SELECT pname FROM supplies s JOIN parts p on(p.pid=s.pid)
JOIN supplier sp on
(sp.sid=s.sid) WHERE sp.sname="ABC";

8
(c) Find the name of all parts that are supplied in quantity greater than 75.
SELECT DISTINCT(pname) FROM parts p, supplies s
WHERE p.pid=s.pid and s.quantity>75;

d) Find the number of parts supplied by “ABC Company”.


SELECT sname, nos FROM(SELECT s.sid,sp.sname,COUNT(p.pid) as nos
FROM supplies s JOIN parts p on
(p.pid=s.pid) JOIN supplier sp on(sp.sid=s.sid)
WHERE sp.sname="ABC" GROUP BY s.sid)

e) Find the name of all suppliers who supply more than 5 parts.
SELECT sname,nos FROM(SELECT s.sid,sp.sname,COUNT(p.pid) as nos
FROM supplies s JOIN parts p on
(p.pid=s.pid) JOIN supplier sp on(sp.sid=s.sid) GROUP BY s.sid) as T
WHERE nos>5

9
Sample data from table

10
SELECT Query Example 2 (Employee, Company, Works, Supervisor)
emp (ss, name)
cmp (cname, address)
works (ss, cname)
super (s_ss, e_ss)
Write relational algebra and SQL queries for each of the following cases:
a) Find the names of all supervisors that work in companies whose address equals “Cuperito‟.
SELECT DISTINCT(e.name) FROM emp e, super s, works w, cmp c
WHERE c.address="Cuperito" AND e.ss=s.s_ss AND s.s_ss=w.ss AND w.cname=c.cname;

b) Find the name of all the companies who have more than 1 supervisors.
SELECT cname, COUNT(cname) as NOS
FROM (SELECT c.cname, COUNT(s.s_ss) AS nos FROM cmp c, super s, works w
WHERE c.cname=w.cname AND w.ss=s.s_ss GROUP BY s.s_ss) as T
GROUP BY cname
HAVING NOS>1;

c) Find the name of supervisor who has the largest number of employees.
SELECT name, MAX(noe)
FROM (SELECT e.name, s_ss, COUNT(s.e_ss) AS noe FROM emp e, super s
WHERE e.ss=s.s_ss GROUP BY s_ss) as T;

Sample Table Data

11
Works Table

Cmp Table

Practical Examples of all the Sql syntax:

1. DDL.
DDL, commonly known as data definition language, is a type of
language which helps to create the structure of the database and
restructure of database objects.

Some of the DDL statements are: CREATE, ALTER, DROP etcetera..

 Create database according to the topic.

Syntax: Create database hospital_management_system;

12
 Use the created database and create table using every
constraints.

2. DML.
DML, commonly known as data manipulation language, is a part of sql
that allows manipulation of data within object of a relational object.

Some of the DML statements are: INSERT, UPDATE, DELETE.

 INSERT (any 5 record).

13
 Update (any 3 example).

Example no 1:

Example no 2:

Example no 3:

Table along with all the update:

 Delete (any 3 example).

14
Example no 1:

Example no 2:

Example no 3:

Table representing all the deletes:

3. DQL.
DQL, commonly known as data query language, is a part of sql that
allows the user to display the particular data. Basically, it is use for
smart search of required data.
The prominent DQL statement is SELECT.

 Use of select statement:

15
 Use of AND, OR, NOT operator.

Example of AND operator: It gives intersection value.

Question: Display pid, pname, pbed, fee whose gender is male


and location is from butwal.

Example of OR operator: It gives union value.

Question: Display pid, pname, pbed, fee whose gender is male or


location is from butwal.

Example of NOT operator along with AND:

Question: Display pid, pname, pbed whose fee is 5000 and


gender is not male.

16
Example of NOT operator along with OR:

Question: Display pid, pname, pbed whose fee is 5000 or gender


is not male.

Example of NOT operator along with NOT and AND:

Question: Display pid, pname, pbed whose fee is not 5000 and
gender is also not male.

 Use of order by clause (any 2 example).

Example of descending order:

Question: Display pid, pname, fee in decending order.

Example of ascending order:

Question: Display pid, pname, fee in ascending order.

17
 Use of group by, having clause (any 2 example).

Example of group by clause:

Question: Display gender and total fee and grouping them into
gender.

Example of group by clause along with having:

Question: Display gender and total fee and grouping them into
gender having total fee greater than 12000.

 Wildcard operator and Like clause ( any 5 example).

Example no 1:

Question: Display all record of the patient whose name start


with “R”.

Example no 2:

Question: Display all record of the patient whose location ends


with “l”.

18
Example no 3:

Question: Find pid, pname in which pname “it” in anywhere.

Example no 4:

Question: Find pid, pname, fee in which pname has “I” at its
second place.

Example no 5:

Question: Find all records of patient whose name starts with “r”
and ends with “m”.

 SQL function (any 5 example).

19
Example no 1: Sum function.

Question: sum of fee.

Example no 2: count function

Question: COUNT PATIENT NAME:

Example no 3: MIN FUNCTION.

Question: find minimum fee.

Example no 4:

Question: find maximum fee.

Example no 5:

Question: find average of fee.

20
21

You might also like