0% found this document useful (0 votes)
45 views8 pages

Worksheet - DBMS CASE STUDY

Uploaded by

shamitaramesh9
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)
45 views8 pages

Worksheet - DBMS CASE STUDY

Uploaded by

shamitaramesh9
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/ 8

WORKSHEET - DATABASE MANAGEMENT SYSTEM

Write the SQL Commands for the following questions based on the table OPD.
TABLE: OPD
REGNO NAME AGE DEPARTMENT DATEOFREG CHARGES GENDER
R0123 Arpita 62 ENT 2000-01-20 500 M
R0124 Jai 55 Orthopedic 2002-05-22 400 M
R0125 Kamal 34 Gen. Physician 2012-03-14 500 M
R0126 Arun 25 Cardiology NULL 800 M
R0127 Neha 30 ENT 2014-12-16 600 F
R0128 Neetu 28 Cardiology 2015-07-13 500 F
R0129 Ankit 27 Orthopedic NULL 300 F
1) Insert a record into the table OPD using the following data.
REGNO – R0122, NAME – Jilesha, AGE – 32, DEPARTMENT – Cardiology, CHARGES – 700,
GENDER - F (DATEOFREG is unknown)
INSERT INTO OPD (REGNO, NAME, AGE, DEPARTMENT, CHARGES, GENDER)
VALUES (‘R0122’, ‘Jilesha’, 32, ‘Cardiology’, 700, ‘F’)
2) Add a column EXPERIENCE with datatype integer(10) and NOT NULL constraint.
ALTER TABLE OPD ADD COLUMN EXPERIENCE integer(10) NOT NULL;
3) Display the records of the ENT department from table OPD in alphabetical order as per the name of
the doctors.
SELECT * FROM OPD WHERE DEPARTMENT= ‘ENT’ ORDER BY NAME;
4) Display the Name, Department and charges whose charges are in the range of 500 to 1000.
SELECT NAME, DEPARTMENT, CHARGES FROM OPD
WHERE CHARGES BETWEEN 500 and 1000;
5) Display all the records excluding Gen. Physician Department.
SELECT * FROM OPD WHERE DEPARTMENT < > ‘Gen. Physician’;
Write the SQL Commands for the following questions based on the table OPD.
1) Display REGNO, NAME, DEPARTMENT from the table OPD whose DATEOFREG is not known.
SELECT REGNO, NAME, DEPARTMENT FROM OPD WHERE DATEOFREG IS NULL;
2) Display the records from the table OPD whose name starts with ‘A’ and contains ‘n’ in it.
SELECT * FROM OPD WHERE NAME LIKE ‘A%n%’;
3) Display the unique values of the DEPARTMENT column of the table OPD.
SELECT DISTINCT DEPARTMENT FROM OPD;
Write the output for the following SQL Commands based on the table OPD.
4) SELECT GENDER, COUNT(*) FROM OPD GROUP BY GENDER;
GENDER COUNT(*)

M 4

F 3
5) SELECT DEPARTMENT, MAX(CHARGES) AS ‘Highest Charge’ FROM OPD
HAVING COUNT(*)>1;
DEPARTMENT Highest Charge

ENT 600

ORTHOPAEDIC 400

CARDIOLOGY 800
TABLE: WORKER
WNO WNAME DOJ PAY GENDER DCODE
1001 George K 2013-09-02 75000 MALE D01
1003 Mohitesh 2013-02-03 62000 MALE D05
1002 Anil Jha 2014-01-17 NULL MALE D04
1004 Manila Sahai 2012-12-09 72000 FEMALE D01
1005 R Sahana 2013-11-18 74000 MALE D02
1006 Jaya Priya 2014-06-09 66000 FEMALE D05
TABLE: DEPT
DCODE DEPARTMENT CITY

D01 MEDIA DELHI

D02 MARKETING DELHI

D03 INFRASTRUCTURE MUMBAI

D05 FINANCE KOLKATA

D04 HUMAN RESOURCE MUMBAI

Write the output for the following SQL Queries based on the relations WORKER and DEPARTMENT.
1) SELECT COUNT(DISTINCT DCODE) FROM WORKER;
COUNT(DISTINCT DCODE)

4
2) SELECT DCODE, SUM(PAY) AS “TOTAL PAY” FROM WORKER GROUP BY DCODE
HAVING COUNT(*) > 1;
DCODE TOTAL PAY

D01 147000

D05 128000

3) SELECT WNAME, DEPARTMENT, CITY


FROM WORKER W, DEPARTMENT D
WHERE W.DCODE=D.DCODE AND WNO>1003;

WNAME DEPARTMENT CITY

Manila Sahai MEDIA DELHI

Jaya Priya FINANCE KOLKATA

4) SELECT WNO, WNAME, DEPARTMENT FROM WORKER W RIGHT JOIN DEPARTMENT D


ON W.DCODE=D.DCODE;
WNO WNAME DEPARTMENT

1001 George K MEDIA

1004 Manila Sahai MEDIA

1005 R Sahana MARKETING

NULL NULL INFRASTRUCTURE

1003 Mohitesh FINANCE

1006 Jaya Priya FINANCE

1002 Anil Jha HUMAN RESOURCE

5) SELECT MIN(PAY) FROM WORKER


WHERE DOJ>’2013-01-01’;
MIN(PAY)

62000

6) SELECT GENDER, AVG(PAY) AS “AVERAGE PAY”


FROM WORKER
GROUP BY GENDER;
GENDER AVERAGE PAY

MALE 70333.33

FEMALE 69000.00
Write the SQL commands for the following based on the table LAB.
1) Increase the capacity of all the labs by 10 students which are on the I floor.
UPDATE LAB SET CAPACITY = CAPACITY + 10
WHERE FLOOR = ‘I’;
2) Remove the LANGUAGE LAB record from the table LAB.
DELETE FROM LAB WHERE LABNAME=’LANGUAGE’;
3) Add Primary key constraint to the column LABNO.
ALTER TABLE LAB ADD PRIMARY KEY(LABNO);
TABLE: LAB
LABNO LABNAME INCHARGE CAPACITY FLOOR

L0001 CHEMISTRY Daisy 20 I

L0002 BIOLOGY Venky 20 II

L0003 MATH Preethi 15 I

L0004 LANGUAGE Mary Slim 32 III

L0005 COMPUTER Janani 30 II


TABLE: COMPUTER
PROD_ID PROD_NAME PRICE COMPANY TYPE

P0001 MOUSE 200 LOGITECH INPUT

P0002 LASER PRINTER 4000 CANON OUTPUT

P0003 KEYBOARD 500 LOGITECH INPUT

P0004 JOYSTICK 1000 IBALL INPUT

P0005 SPEAKER 1200 CREATIVE OUTPUT

P0006 DESKJET PRINTER 4300 CANON OUTPUT


TABLE: SALES
PROD_ID QTY_SOLD QUARTER

P0002 4 1

P0003 2 2

P0001 3 2

P0004 5 1

Write the outputs of the SQL Queries 4 to 7 based on the relations COMPUTER and SALES.

4) SELECT MIN(PRICE), MAX(PRICE)


FROM COMPUTER;
MIN(PRICE) MAX(PRICE)

200 4300

5) SELECT COMPANY, SUM(PRICE) FROM COMPUTER


GROUP BY COMPANY HAVING COUNT(COMPANY)>1;
COMPANY COUNT(*)

LOGITECH 700

CANON 8300
6) SELECT PROD_NAME, QTY_SOLD FROM COMPUTER C.SALES S
WHEREC.PROD_ID = S.PROD_ID AND TYPE= ‘INPUT’;
PROD_NAME QTY_SOLD

MOUSE 3

KEYBOARD 2

JOYSTICK 5
7) SELECT * FROM COMPUTER NATURAL JOIN SALES;
PROD_ID PROD_NAME PRICE COMPANY TYPE QTY_SOLD QUARTER

P0001 MOUSE 200 LOGITECH INPUT 3 2

P0002 LASER 4000 CANON OUTPUT 4 1


PRINTER

P0003 KEYBOARD 500 LOGITECH INPUT 2 2

P0004 JOYSTICK 1000 IBALL INPUT 5 1


TABLE: PRODUCT
P_ID PNAME MANUFACTURER PRICE DISCOUNT

TP01 Talcum Powder LAK 40 NULL

FW05 Face Wash ABC 45 5

BS14 Bath Soap SEN 55 10

SH06 Shampoo XYZ 120 NULL

FW12 Face Wash XYZ 95 12

SH10 Talcum Powder ABC 70 NULL


TABLE: CLIENT
C_ID CNAME CITY P_ID

01 Cosmetic Shop Delhi TP01

02 Total Health Mumbai FW05

03 Live Life Delhi BS01

04 Pretty Woman Mumbai SH06

05 Dreams Bengaluru FW12

Write the SQL commands for the following questions based on the tables PRODUCT and CLIENT.
1) To display details of products whose manufacturer is either ABC or XYZ.
SELECT * FROM PRODUCT WHERE MANUFACTURER IN (‘ABC’, ‘XYZ’);
2) To display Product name, manufacturer and price for all the products that are giving discount.
SELECT PNAME, MANUFACTURER, PRICE FROM PRODUCT
WHERE DISCOUNT IS NOT NULL;
3) To display Product name and price for all the products whose name does not end with ‘Wash’.
SELECT PNAME, PRICE FROM PRODUCT WHERE PNAME NOT LIKE ‘%Wash’;
4) To display the P_ID, Product name and Client name for all the clients whose city is Delhi.
SELECT P. P_ID, PNAME, CNAME FROM PRODUCT P, CLIENT C
WHERE P. P_ID = C. P_ID and C. CITY = ‘Delhi’;
Write the output for the following SQL Queries based on the tables given PRODUCT and CLIENT.
5) SELECT P_ID, PNAME, CNAME, CITY FROM PRODUCT P LEFT JOIN CLIENT C
ON P. P_ID = C. P_ID ;
P_ID PNAME CNAME CITY

TP01 Talcum Powder Cosmetic Shop Delhi

FW05 Face Wash Total Health Mumbai

BS14 Bath Soap NULL NULL

SH06 Shampoo Pretty Woman Mumbai

FW12 Face Wash Dreams Bengaluru

SH10 Talcum Powder NULL NULL


6) SELECT PNAME, COUNT(*) FROM PRODUCT ORDER BY PNAME;
PNAME COUNT(*)

Bath Soap 1

Face Wash 2

Shampoo 1

Talcum Powder 2

7) SELECT PNAME, MIN(PRICE) AS “LOWEST PRICE” FROM PRODUCT


GROUP BY PNAME HAVING COUNT(*)>1;
PNAME LOWEST PRICE

Talcum Powder 40

Face Wash 45

8) SELECT DISTINCT CITY FROM CLIENT;


CITY

Delhi

Mumbai

Bengaluru

9) SELECT COUNT(DISCOUNT) FROM PRODUCT;


COUNT(DISCOUNT)

3
10) SELECT P_ID, PNAME, CNAME, CITY FROM PRODUCT P RIGHT JOIN CLIENT C
ON P. P_ID = C. P_ID ;
P_ID PNAME CNAME CITY

TP01 Talcum Powder Cosmetic Shop Delhi

FW05 Face Wash Total Health Mumbai

NULL NULL Live Life Delhi

SH06 Shampoo Pretty Woman Mumbai

FW12 Face Wash Dreams Bengaluru

1) Write a database connectivity program to increase the salary of employee by 5000


whose empno is 1005 from the table 'employee' in MySQL database 'EMPDB'. Fields
of the table are below.

ASSERTION & REASONING:

(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation for A
(c) A is True but R is False
(d) A is false but R is True

1) Assertion (A): COUNT(*) returns the total number of records from a relation and
SELECT COUNT(NAME) FROM EMPLOYEE;
Above command returns number of records present in NAME column ignoring null
values.
Reasoning (R): Aggregate functions can be used with columns with only numerical
values. Ans: c)
2) Assertion(A): The resultset refers to a logical set of records that are fetched from the
database by executing an SQL query.
Reason(R): Resultset stored in a cursor object can be extracted by using fetch(...)
functions. ANS: b)
3) Assertion: The internet is a collection of interconnected computer networks, linked
by transmission medium such as fibre optic cables, transmission wires, wireless
connections, etc.
Reason: World Wide Web is a collection of websites or web pages stored in web
servers and connected to local computers through the internet. ANS: b)
4) Assertion ( A): In SQL, the aggregate function AVG() calculates the average value on
a set of values and produces a single result.
Reason ( R): The aggregate functions are used to perform some fundamental
arithmetic tasks such as Min(), Max(), Sum() etc ANS: b)
5) Assertion (A): COUNT function ignores DISTINCT.
Reason ( R ): DISTINCT ignores duplicate values.
6) Assertion (A): Order By clause is used to sort the records in MySQL tables.
Reason (R) : For sorting, ASC and DESC keywords are mandatory.
7) Assertion (A): UNIQUE keyword ensures no duplicate values in a table.
Reason (R): DISTINCT is similar to UNIQUE.
8) Assertion (A): WHERE clause cannot be used with aggregate functions.
Reason (R): Having clause is used to place condition on group of rows.
9) Assertion (A): SQL SELECT provides clauses for summarizing results.
Reason (R): The GROUP BY clause allows to create summarised results.
10) Assertion (A) : A protocol means the set of rules that are applicable for a network.
Reason (R): STP is a networking protocol.
11) Assertion (A): Cartesian Product is also called as cross join.
Reason (R): SQL join which relates 2 tables when no condition is specified is cross
join.
12) Assertion(A): Inner Join in SQL retrieves the records that have matching values in
both the tables.
Reason (R): Left join and Right join are the variants of Inner join.
13) Assertion (A): Circuit Switching networks are specifically designed for Voice
communication.
Reason (R): Delay time between the data units is uniform in circuit switching
networks.
14) Assertion (A): IP address IPv4 is a 32 bit address IPv6 is a 128 bit address.
Reason (R): Each octet in IPv4 is separated by colon and it is separated by dot in
IPv6.
15) Assertion (A): Lower bandwidth leads to higher data transfer rate.
Reason (R): Bandwidth means the transmission capacity of a network over a specific
period of time. Data transfer rate is the actual amount of data transferred per unit time.

You might also like