56
1 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019 DBMS LABORATORY WITH MINI PROJECT 17CSL58 DBMS LABORATORY WITH MINI PROJECT (17CSL58) LAB MANUAL For V SEMESTER MAHARAJA INSTITUTE OF TECHNOLOGY, MYSORE DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING MIT MYSORE

DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

1 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

DBMS LABORATORY WITH MINI PROJECT (17CSL58)

LAB MANUAL

For V SEMESTER

MAHARAJA INSTITUTE OF TECHNOLOGY, MYSORE

DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING

MIT MYSORE

Page 2: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

2 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

VISION AND MISSION OF INSTITUTE

VISION OF THE INSTITUTE

“To be recognized as a premier technical and management institution promoting extensive

education fostering research, innovation and entrepreneurial attitude"

MISSION OF THE INSTITUTE

1. To empower students with indispensable knowledge through dedicated teaching and

collaborative learning.

2. To advance extensive research in science, engineering and management disciplines.

3. To facilitate entrepreneurial skills through effective institute-industry collaboration and

interaction with alumni.

4. To instill the need to uphold ethics in every aspect.

5. To mould holistic individuals capable of contributing to the advancement of the society.

VISION, MISSION, PROGRAM EDUCATIONAL OBJECTIVES AND PROGRAM SPECIFIC OUTCOME

OF DEPARTMENT

VISION OF THE DEPARTMENT

To be recognized as the best centre for technical education and research in the field of

information science and engineering.

MISSION OF THE DEPARTMENT

⮚ To facilitate adequate transformation in students through a proficient teaching learning

process with the guidance of mentors and all-inclusive professional activities.

⮚ To infuse students with professional, ethical and leadership attributes through industry

collaboration and alumni affiliation.

⮚ To enhance research and entrepreneurship in associated domains and to facilitate real

time problem solving.

PROGRAM EDUCATIONAL OBJECTIVES:

⮚ Proficiency in being an IT professional, capable of providing genuine solutions to

information science problems.

Page 3: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

3 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

⮚ Capable of using basic concepts and skills of science and IT disciplines to pursue greater

competencies through higher education.

⮚ Exhibit relevant professional skills and learned involvement to match the requirements of

technological trends.

PROGRAM SPECIFIC OUTCOME:

Student will be able

⮚ PSO1: Apply the principles of theoretical foundations, data Organizations, networking

concepts and data analytical methods in the evolving technologies.

⮚ PSO2:Analyse proficient algorithms to develop software and hardware competence in

both professional and industrial areas

Page 4: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

4 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

General Lab Guidelines: • Conduct yourself in a responsible manner at all times in the laboratory. Intentional

misconduct will lead to the exclusion from the lab. • Do not wander around, or distract other students, or interfere with the laboratory

experiments of other students. • Read the handout and procedures before starting the experiments. Follow all written and

verbal instructions carefully. If you do not understand the procedures, ask the instructor or teaching assistant.

• Attendance in all the labs is mandatory, absence permitted only with prior permission from Class teacher.

• The workplace has to be tidy before, during and after the experiment. • Do not eat food, drink beverages or chew gum in the laboratory. • Every student should know the location and operating procedures of all Safety equipment

including First Aid Kit and Fire extinguisher. DO’S:-

Uniform and ID card are must.

Strictly follow the procedures for conduction of experiments.

Records have to be submitted every week for evaluation.

Chairs and stools should be kept under the workbenches when not in use.

After the lab session, switch off every supply, disconnect and disintegrate the experiments

and return the components.

Keep your belongings in designated area.

Never use damaged instruments, wires or connectors. Hand these parts to the instructor/

teaching assistant.

Sign the log book when you enter/leave the laboratory.

DONT’S:-

Don't touch open wires unless you are sure that there is no voltage. Always disconnect the

plug by pulling on the connector body not by the cable. Switch off the supply while you

make changes to the experiment.

Don’t leave the experiment table unattended when the experimental setup supply is on.

Students are not allowed to work in laboratory alone or without presence of the teaching

staff/ instructor.

No additional material should be carried by the students during regular labs.

Avoid stepping on electrical wires or any other computer cables.

Page 5: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

5 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Course objectives: This course will enable students to

Foundation knowledge in database concepts, technology and practice to groom students into well-

informed database application developers.

Strong practice in SQL programming through a variety of database problems.

Develop database applications using front-end tools and back-end DBMS. Description (If any):

PART-A:

SQL programming (Max. Exam Marks, 50)

Design, develop, and implement the specified queries for the following problems using Oracle, My

SQL, MY SQL Server, or any other DBMS under LINUX/Windows environment.

Create Schema and insert at least 5 records for each table. Add appropriate database constraints.

PART-B:

Mini project (Max. Exam Marks, 30)

Use Java. C#, PHP, Python, or any other similar front-end tool.

All applications must be demonstrated on desktop/laptop as a stand-alone or web based application

(Mobile apps on Android/IOS are not permitted).

PART A: SQL PROGRAMMING

A. Consider the following schema for a Library Database:

BOOK (Book_ id, Title, Publisher_ Name, Pub_ Year)

BOOK_AUTHORS (Book_ id, Author_ Name)

PUBLISHER (Name, Address, Phone)

BOOK_COPIES (Book_ id, Branch_ id, No_ of_ Copies)

BOOK_LENDING (Book_ id, Branch_ id ,Card_ No, Date_ Out, Due_ Date)

LIBRARY_BRANCH (Branch_ id, Branch_ Name, Address)

Page 6: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

6 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Write SQL queries to

A. Retrieve details of all books in the library – id, title, name of publisher, authors, number of copies in

each branch, etc.

B. Get the particulars of borrowers who have borrowed more than 3 books, but from Jan 2017 to Jun 2017.

C. Delete a book in BOOK table. Update the currents of other tables of reflect this data manipulation

Operation.

D. Partition the BOOK table based on year of publication. Demonstrate its working with a simple query.

E. Create a view of all books and its number of copies that are currently available in the Library.

Solution:

ERDigram:

Page 7: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

7 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Schema diagram:

BOOK

Book_ id

title Publisher_ Name Publisher_ year

BOOK_AUTHOR

Book_ id

Author_ name

PUBLISHER

name

address phone

BOOK_COPIES

Book_ id

Branch_ id No_ of_ copies

BOOK_LENDING

Book_ id

Branch_ id Card_ no Date_ out Due_ date

LIBRARY_BRANCH

Branch_ id

Branch_ name address

Table Creation

CREATE TABLE PUBLISHER(NAME VARCHAR(20) PRIMARY KEY,ADDRESS

VARCHAR(20),PHONE REAL);

CREATE TABLE BOOK(BOOK_ID INT PRIMARY KEY,TITLE CHAR(10),PUBLISHER_NAME

CHAR(15),PUBLISHER_YEAR INT,FOREIGN KEY(PUBLISHER_NAME) REFERENCES

PUBLISHER(NAME) ON DELETE CASCADE);

Page 8: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

8 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

CREATE TABLE LIBRARY_BRANCH(BRANCH_ID INT PRIMARY KEY,BRANCH_NAME

CHAR(10),ADDRESS VARCHAR(15));

CREATE TABLE BOOK_AUTHORS(BOOK_ID INT,AUTHOR_NAME CHAR(10),FOREIGN

KEY(BOOK_ID) REFERENCES BOOK(BOOK_ID) ON DELETE CASCADE);

CREATE TABLE BOOK_LENDING(BOOK_ID INT,BRANCH_ID INT,CARD_NO INT,DATE_OUT

DATE,DUE_DATE DATE,PRIMARY KEY(BOOK_ID,BRANCH_ID,CARD_NO),FOREIGN

KEY(BOOK_ID) REFERENCES BOOK(BOOK_ID) ON DELETE CASCADE,FOREIGN

KEY(BRANCH_ID) REFERENCES LIBRARY_BRANCH(BRANCH_ID) ON DELETE CASCADE);

CREATE TABLE BOOK_COPIES(BOOK_ID INT,BRANCH_ID INT,NO_OF_COPIES INT,FOREIGN

KEY(BOOK_ID) REFERENCES BOOK(BOOK_ID) ON DELETE CASCADE,FOREIGN

KEY(BRANCH_ID) REFERENCES LIBRARY_BRANCH(BRANCH_ID) ON DELETE

CASCADE,PRIMARY KEY(BOOK_ID,BRANCH_ID));

Table description

DESC PUBLISHER;

DESC BOOK;

DESC LIBRARY_BRANCH;

Page 9: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

9 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

DESC BOOK_AUTHORS;

DESC BOOK_LENDING;

DESC BOOK_COPIES;

Page 10: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

10 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Insertion of values to tables:

INSERTINTO PUBLISHER VALUES(“ANUAMMUBOOKS”,”SRIRAMRKNAGAR”,”8797546021”);

INSERT INTO PUBLISHER VALUES(“BHAVANISTORE”,”KARNATAKABAR”,”9900778821”);

INSERT INTO PUBLISHER VALUES(“RAJBOOKSTALL”,”SATALLITE@12”,”9252459821”);

INSERT INTO PUBLISHER VALUES(“SNEHABANDHU”,”MANDYA123”,”9380577730”);

INSERT INTO PUBLISHER VALUES(“SPOO@SHBOOKS”,”NEARBEMLARCH”,”8969361282”);

INSERT INTO PUBLISHER VALUES(“SRI SAI”,”DEVEGOWDANAHUNDI”,”7090454640”);

INSERT INTO BOOK VALUES(“100”,”OOMD”,”SRI SAI”,”1996”);

INSERT INTO BOOK VALUES(“101”,”CMPTRNTWK”,”SNEHABANDHU”,”1992”);

INSERT INTO BOOK VALUES(“102”,”AUTOMATA”,”RAJBOOKSTALL”,”2000”);

INSERTB INTO BOOK VALUES(“103”,”CSHARP”,”SPOO@ASHBOOKS”,”2012”);

INSERT INTO BOOK VALUES(“104”,”MANAGEMENT”,”SRI SAI”,”1996”);

INSERT INTO BOOK VALUES(“105”,”DATABASEMS”,”BHAVANISTORE”,”1899”);

INSERT INTO LIBRARY_BRANCH VALUES(“1000”,”BRANCH1”,”GROUNDFLOAR”);

INSERT INTO LIBRARAY_BRANCH VALUES(“1001”,”BRANCH2”,”GFROWF”);

INSERT INTO LIBRARY_BRANCH VALUES(“1002”,”BRANCH1”,”LFTSIDEROW7”);

INSERT INTO LIBRARY_BRANCH VALUES(“1003”,”BRANCH3”,”RGHTSIDEROW7);

INSERT INTO LIBRARY_BRANCH VALUES(“1004”,”BRANCH4”,”OPPOSITEFLOAR”);

INSERT INTO LIBRARY_BRANCH VALUES(“1005”,”BRANCH5”,”ECEFLOAR”);

INSERT INTO BOOK_AUTHORS VALUES(“100”,”NAWATHI”);

INSERT INTO BOOK_AUTHORS VALUES(“100”,”NAWATHI”);

INSERT INTO BOOK_AUTHORS VALUES(“101”,”THRIPATI”);

INSERT INTO BOOK_AUTHORS VALUES(“102”,”PADMAREDDY”);

INSERT INTO BOOK_AUTHORS VALUES(“103”,”KRISHNA”);

Page 11: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

11 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

INSERT INTO BOOK_LENDING VALUES(“100”,”1000”,”50”,”2017/01/03”,”2017/06/26”);

INSERT INTO BOOK_LENDING VALUES(“101”,”1001”,”50”,”2017/01/26”,”2017/06/26”);

INSERT INTO BOOK_LENDING VALUES(“102”,”1002”,”50”,”2017/01/15”,”2017/06/26”);

INSERT INTO BOOK_LENDING VALUES(“103”,”1003”,”50”,”2018/01/26”,”2018/06/03”);

INSERT INTO BOOK_LENDING VALUES(“104”,”1004”,”54”,”2017/01/03”,”2017/06/03”);

INSERT INTO BOOK_COPIES VALUES(“101”,”1000”,”3”);

INSERT INTO BOOK_COPIES VALUES(“100”,”1004”,”4”);

INSERT INTO BOOK_COPIES VALUES(“101”,”1006”,”2”);

INSERT INTO BOOK_COPIES VALUES(“103”,”1003”,”5”);

INSERT INTO BOOK_COPIES VALUES(“104”,”1002”,”5”);

SELECT * FROM PUBLISHER;

SELECT * FROM BOOK;

Page 12: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

12 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

SELECT * FR0M LIBRARY_BRANCH;

SELECT * FR0M BOOK_AUTHORS;

SELECT * FROM BOOK_LENDING;

Page 13: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

13 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

SELECT * FROM BOOK_COPIES;

Queries:

1. Retrieve details of all books in the library_ id, title, name of publisher, authors, number of

copies in each branch, etc.

SELECTPUBLISHER_NAME,BRANCH_ID,TITLE,AUTHOR_NAME,NO_OF_COPIES

FROM BOOK b, BOOK_COPIES c, BOOK_AUTHOR a WHERE b. BOOK_ID=a. BOOK_ID

AND b. BOOK_ID=c. BOOK_ID;

2. Get the particulars of borrowers who have borrowed more than 3 books, but from Jan 2017

to Jun 2017.

Page 14: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

14 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

SELECT CARD_NO FROM BOOK_LENDING WHERE DATE_OUT BETWEEN “2017/01/03”

AND “2017/06/26” GROUP BY CARD_NO HAVING COUNT(*)>=3;

3. Delete a book in BOOK table, Update the contents of other tables to reflect this data

manipulation Operation.

DELETE FROM BOOK WHERE BOOK_ID=100;

SELECT * FROM BOOK;

SELECT * FROM BOOK_LENDING;

SELECT * FROM BOOK_COPIES;

Page 15: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

15 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

4. Partition the BOOK table based on year of publication. Demonstrate its working with a simple

query.

CREATE VIEW P_YEAR AS (SELECT PUBLISHER_YEAR FROM BOOK GROUP BY

PUBLISHER_YEAR);

SELECT * FROM PUBLISHER_YEAR;

5. Create a view of all books and its number of copies that are currently available in the library.

CRAETE VIEW CUR_AVAI AS (SELECT b. BOOK_ID, NO_OF_COPIES, TITLE FROM

BOOK_COPIES b, LIBRARY_BRANCH l, BOOK c WHERE b. BRANCH_ID=l. BRANCH_ID

AND c. BOOK_ID=b. BOOK_ID);

SELECT * FROM CUR_AVAI;

B. Consider the following schema foe Order Database:

SALESMAN(Salesman_ id, Name, City, Commission)

CUSTOMER(Customer_ id, Customer_ name, Grade, Salesman_ id)

ORDERS(Order_ no, Purchase_ amount, Order_ date, Customer_ id, Salesman_ id)

Page 16: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

16 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Write SQL queries to

1. Count the customers with grades above Banaglore’s average.

2. Find the name and numbers of all salesman who had more than one customer.

3. List all salesman and indicate those have and don’t have customers in their cities(use UNION

operation).

4. Create a view that finds the salesman who has the customer with the highest order of a day.

5. Demonstrate the DELETE operation by removing salesman with id 1000. All his orders must be

deleted.

Solution:

ER – Diagram:

Schema Digram:

SALESMAN

Salesman_ id

name city commission

Page 17: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

17 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

CUSTOMER

Customer_ id

Customer_ name city grade Salesman_ id

ORDERS

Order_ no

Purchase_ amount Order_ date Customer_ id Salesman_ id

Table creation:

CREATE TABLE SALESMAN(SALESMAN_ID INT PRIMARY KEY,NAME CHAR(20),CITY

CHAR(20),COMMISSION REAL);

CREATE TABLE CUSTOMER(CUSTOMER_ID INT PRIMARY KEY,CUSTOMER_NAME

CHAR(20),CITY CHAR(20),GRADE INT,SALESMAN_ID INT,FOREIGN KEY(SALESMAN_ID)

REFERENCES SALESMAN(SALESMAN_ID) ON DELETE SET NULL);

CREATE TABLE ORDERS(ORDER_NO INT PRIMARY KEY,PURCHASE_AMOUNT

REAL,ORDER_DATE DATE,CUSTOMER_ID INT,FOREIGN KEY(CUSTOMER_ID) REFERENCES

CUSTOMER(CUSTOMER_ID),SALESMAN_ID INT,FOREIGN KEY(SALESMAN_ID) REFERENCES

SALESMAN(SALESMAN_ID) ON DELETE CASCADE);

Table description;

DESC SALESMAN;

DESC CUSTOMER;

Page 18: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

18 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

DESC ORDERS;

Insertion of values to tables:

INSERT INTO SALESMAN VALUES(“1000”,”BHUVANESH K”,”BANGLORE”,”12000”);

INSERT INTO SALESMAN VALUES(“1001”,”PRAGATHI”,”BANGLORE”,”15000”);

INSERT INTO SALESMAN VALUES(“1002”,”VASUDEVAPRASAD”,”MANGLORE”,”10000”);

INSERT INTO SALESMAN VALUES(“1003”,”GURUPRASADKONDI”,”MYSORE@123”,”19000”);

INSERT INTO SALESMAN VALUES(“1004”,”SRISAI SALERS”,”MANDYA”,”25000”);

INSERT INTO SALESMAN

VALUES(“1005”,”BOOKTRIBUTERS”,”HANUMANTHNAGAR”,”16200”);

INSERT INTO SALESMAN VALUES(“SHOWROOMGALAXY”,”BIDAR”,”14900”);

INSERT INTO CUSTOMER VALUES(“100”,”SPOORTHIASHWIN”,”BIDAR”,”10”,”1000”);

INSERT INTO CUSTOMER

VALUES(“100”,”AMRUTHANUKASHYAP”,”MANGLORE”,”8”,”1000”);

Page 19: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

19 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

INSERT INTO CUSTOMER VALUES(“102”,”RAJESHWARI”,”MANGLORE”,”5”,”1002”);

INSERT INTO CUSTOMER VALUES(“103”,“NISHAKGOWDA”,”MANGLORE”,”9”,”1001”);

INSERT INTO CUSTOMER VALUES(“104”,“SATHWIK”,”MANDYA”,”10”,”1004”);

INSERT INTO CUSTOMER VALUES(“105”,”GURUDEVANAYAK”,”BIDAR”,”7”,”1002”);

INSERT INTO CUSTOMER VALUES(“106”,”VASUMURTHI”,”MYSORE@123”,”9”,”1003”);

INSERT INTO ORDERS VALUES(“10”,”23000”,”2019/09/17”,”100”,”1000);

INSERT INTO ORDERS VALUES(“11”,”26455”,”2019/06/03”,”102”,”1001’);

INSERT INTO ORDERS VALUES(“12”,”30002”,”2019/01/03”,”103”,”1002”);

INSERT INTO ORDERS VALUES(“13”,”17003”,”2019/07/17”,”105”,”1003”);

INSERT INTO ORDERS VALUES(“14”,“45255”,”2019/05/13”,”106”,”1004”);

INSERT INTO ORDERS VALUES(“15”,”32000”,”2019/07/23”,”101”,”1000”);

INSERT INTO ORDERS VALUES(“16”,”27000”,”2019/05/23”,”104”,”1002”);

INSERT INTO ORDERS VALUES(“17”,”26255”,”2019/09/17”,”104”,”1000”);

SELECT * FROM SALESMAN;

SELECT * FROM CUSTOMER;

Page 20: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

20 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

SELECT * FROM ORDERS;

:

1. Count the customers with grades above banglore’s average.

SELECT COUNT(CUSTOMER_ID),GRADE FROM CUSTOMER WHERE

GRADE>=(SELECT AVG(GRADE) FROM CUSTOMER WHERE

CITY=”BANGLORE”)GROUP BY GRADE;

2. Find the name and numbers of all salesman who has more than one customer.

Page 21: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

21 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

SELECT SALESMAN_ID,NAME FROM SALESMAN WHERE SALESMAN_ID IN(SELECT

SALESMAN_ID FROM CUSTOMER GROUP BY SALESMAN_ID HAVING

COUNT(CUSTOMER_ID)>1);

3. List all the salesman and indicate those who have and don’t have customers in their cities (Use

UNION Operation).

(SELECT SALESMAN_ID, NAME FROM CUSTOMER c, SALESMAN s

WHERE s. SALESMAN_ID=c. SALESMAN_ID AND s. CITY=c. CITY)

UNION

(SELECT SALESMAN_ID, NAME FROM CUSTOMER c, SALESMAN s WHERE s.

SALESMAN_ID=c, SALESMAN_ID AND s. CITY!=c. CITY));

4. Create a view that finds the salesman who has the customer within the highest order of day.

CREATE VIEW SAL_MAX AS(SELECT s. SALESMAN_ID, NAME ,c. ORDER_DATE FROM

SALESMAN s, ORDERS c WHERE c. SALESMAN_ID=s. SALESMAN_ID AND

PURCAHSE_AMOUNT=(SELECT MAX(PURCHASE_AMOUNT) FROM ORDERS o WHERE

o. ORDER_DATE=c. OREDER_DATE;

Page 22: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

22 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

SELECT * FROM SAL_MAX;

5. Demonstrate the DELETE operation by removing salesman with id 1000,but all his orders

must be deleted.

DELETE FROM SALESMAN WHERE SALESMAN_ID=1000;

Page 23: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

23 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

A. Consider the schema for Movie Database

ACTOR(Act_ id, Act_ name, Act_ gender)

DIRECTOR(Dir_ id, Dir_ name, Dir_ phone)

MOVIES(Mov_ id, Mov_ title, Mov_ year, Mov_ lang, dir- id)

MOVIE_CAST(Act_ id, Mov_ id, Role)

RATING(Mov_ id, Rev_ stars)

Write SQL queries to

1. List the titles of all movies directed by ‘Hitchcock’.

2. Find the movie names where one or more actors acted in two or more movies.

3. List all actors who acted in movie before 2000 and also in a movie after 2015 (use JOIN operation).

4. Find the title of movies and number of stars for each movie that has at least one rating and find the

highest number of stars that movie received. Sort the result by movie title.

5. Update rating of all movies directed by “Steven Spielberg’ to 5.

Solution:

ER –Diagram:

Page 24: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

24 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Page 25: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

25 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Schema diagram:

ACTOR

Act_ id Act_ name gender

DIRECTOR

Dir_ id Dir_ name Dir_phone

MOVIES

Mov_ id Mov_ tit Mov_ year Mov_ lang Dir_ id

MOVIE_CAST

Act_ id Mov_ id Role

RATING

Mov_ id Rev_ stars

Table Creation:

CREATE TABLE ACTOR(ACT_ID INT PRIMARY KEY,ACT_NAME CHAR(20), GENDER

CHAR(6));

CRAETE TABLE DIRECTOR(DIR_ID INT PRIMARY KEY,DIR_NAME CHAR(20),DIR_PHONE

REAL);

Page 26: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

26 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

CREATE TABLE MOVIES(MOV_ID INT PRIMARY KEY,MOV_TITLE VARCAHR(20),MOV_YEAR

REAL,MOV_LANG CHAR(10),DIR_ID INT,FOREIGN KEY(DIR_ID) REFERENCES

DIRECTOR(DIR_ID));

CRAETE TABLE MOVIE_CAST(ACT_ID INT,MOV_ID INT,ROLE CHAR(15),PRIMARY

KEY(ACT_ID,MOV_ID),FOREIGN KEY(ACT_ID) REFERENCES ACTOR(ACT_ID),FOREIGN

KEY(MOV_ID) REFERENCES MOVIES(MOV_ID));

CREATE TABLE RATING(MOV_ID INT,REV_STARS INT,FOREIGN KEY(MOV_ID) REFERENCES

MOVIES(MOV_ID));

Insertion of values to tables:

INSERT INTO ACTOR VSLUES(“100”,”PUNITHRAJKUMAR”,”MALE”);

INSERT INTO ACTOR VALUES(“101”,”RAKSHITHAPREM”,”FEMALE”);

INSERT INTO ACTOR VALUES(“102”,”CHIKKANNA”,”MALE’);

INSERT INTO ACTOR VALUES(“103”,”SHARAN”,”MALE”);

INSERT INTO ACTOR VALUES(“104”,”SADHUKOKILA”,”MALE”);

INSERT INTO ACTOR VALUES(“105”,”MANJULA”,”FEMALE”);

INSERT INTO DIRECTOR VALUES(“10”,”HITCHCOCK”,”9933221144”);

INSERT INTO DIRECTOR VALUES(“11”,”STEVEN SPIELBERG”,”9876541234”);

INSERT INTO DIRECTOR VALUES(“12”,”PAVANVODEYAR”,”9632587410”);

INSERT INTO DIRECTOR VALUES(“13”,”YOGRAJBHAT”,”7412589630”);

INSERT INT0 DIRECTOR VALUES(“14”,”S NARAYAN”,”8521479630”);

INSERT INTO DIRECTOR VALUES(“15”,”UPENDRA”,”9631478520”);

Page 27: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

27 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

INSERT INTO MOVIES VALUES(“50”,”RAJAKUMARA”,”2016”,”KANNADA”,”12’);

INSERT INTO MOVIES VALUES(“51”,”50SHADESOFGREY”,”2018”,”ENGLISH”,”10”);

INSERT INTO MOVIES VALUES(“52”,”KANJURING”,”1999”,”ENGLISH”,”11”);

INSERT INTO MOVIES VALUES(“53”,”HEARTATTACK”,”1999”,”TELAGU”,”10”);

INSERT INTO MOVIES VALUES(“54”,”ILUVU”,”2019”,”KANNADA”,”15”);

INSERT INTO MOVIES(“55”,”HALUJENU”,”1998”,”KANNADA”,”14”);

INSERT INTO MOVIE_CAST VALUES(“101”,”52”,”HEROIN”);

INSERT INTO MOVIE_CAST VALUES(“102”,”50”,”COMEDIAN”);

INSERT INTO MOVIE_CAST VALUES(“102”,”51”,”SIDEACTOR”);

INSERT INTO MOVIE_CAST VALUES(“102”,”54”,”COMEDIAN”);

INSERT INTO MOVIE_CAST VALUES(“103”,”50”,”GUESTROLE”);

INSERT INTO MOVIE_CAST VALUES(“103”,”53”,”HERO”);

INSERT INTO MOVIE_CAST VALUES(“104”,”50”,”COMEDIAN”);

INSERT INTO MOVIE_CAST VALUES(“104”,”55”,”COMEDIAN”);

INSERT INTO RATING VALUES(“50”,”5”);

INSERT INTO RATING VALUES(“50”,”5”);

INSERT INTO RATING VALUES(“51”,”5”);

INSERT INTO RATING VALUES(“55”,”5”);

Page 28: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

28 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

INSERT INTO RATING VALUES(“52”,”4”);

INSERT INTO RATING VALUES(“53”,”5”);

INSERT INTO RATING VALUES(“54”,”3”);

INSERT INTO RATING VALUES(“50”,”4”);

INSERT INTO RATING VALUES(“50”,”2”);

SELECT * FROM ACTOR;

SELECT * FROM DIRECTOR;

SELECT * FROM MOVIES;

Page 29: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

29 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

SELECT * FROM MOVIE_CAST;

SELECT * FROM RATING;

Page 30: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

30 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Queries:

1. List the titles of all the movies directed by Hitchcock.

SELECT MOVIE_TITLE FROM DIRECTOR d, MOVIES m WHERE d. DIR_ID=m. DIR_ID

AND DIR_NAME=”HITCHCOCK”;

2. Find the movie names where one or more actors acted in two or more movies.

SELECT MOV-TITLE FROM MOVIES m, MOVIE_CAST v WHERE m. MOV_ID=v. MOV_ID

AND ACT_ID IN(SELECT ACT_ID FROM MOVIE_CAST GROUP BY ACT_ID HAVING

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

3. List all actors who are acted in movie before 2000 and also in a movie after 2015 (use JOIN

operation).

SELECT a.ACT_ ID FROM ACTORS a, MOVIES m, MOVIE_CAST c WHERE a.ACT_

ID=c.ACT_ID AND m. MOV_ID=c.MOV_ID AND MOV_YEAR<2000 AND a.ACT_ID

IN(SELECT b.ACT_ID FROM ACTORS b,MOVIES n,MOVIE_CAST d WHERE

b.ACT_ID=d.ACT_ID AND n.MOV_ID=d.MOV_ID MOV_YEAR>2015);

Page 31: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

31 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

4. Find the title of movies and number of stars for each movies that as at least one rating, and

find the highest number of stars that movie receives, sort the movie title by the name.

SELECT MOV_TITLE,MAX(REV_STARS) FROM MOVIES m, RATING r WHERE m.MOV_

ID=r.MOV_ ID GROUP BY MOV_TITLE HAVING MAX(REV_STARS)>0 ORDER BY

MOV_TITLE;

5. Update the rating of all the movies directed by Steven Spielberg to 5.

UPDATE RATING SET REV_STARS=5 WHERE MOV_ID IN(SELECT MOV_ID FROM

MOVIES WHERE DIR_ID IN(SELECT DIR_ID FROM DIRECTOR WHERE

DIR_NAME=”STEVEN SPIELBERG”));

E. Consider the schema for college Database:

Page 32: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

32 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

STUDENT(USN, Sname, Address, Phone, Gender)

SEMSEC(SSID, Sem, Sec)

CLASS(USN, SSID)

SUBJECT(Subcode, Title, Sem, Credits)

IA_MARKS(USN, Subcode, SSID, Test1, Test2, Test3, FinalIA)

Write SQL queries to

1. List all the students details studying in 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 subjects.

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.

Solution:

ER – Diagram:

Page 33: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

33 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Schema diagram;

STUDENT

USN S name address Phone Gender

SEM_SEC

SSID Sem Sec

CLASS

USN SSID

SUBJECT

Sub code title Sem credits

IA_MARKS

USN Sub code SSID Test1 Test2 Test3 Final ia

TABLE CREATION

CREATE TABLE STUDENT(USN VARCHAR(15) PRIMARY KEY,SNAME CHAR(20),ADDRESS

VARCHAR(20),PHONE REAL,GENDER CHAR(6));

CREATE TABLE SEM_SEC(SSID INT PRIMARY KEY,SEM INT,SEC CHAR(4));

CREATE TABLE CLASS(USN VARCHAR(15),SSID INT,PRIMARY KEY(USN,SSID),FOREIGN

KEY(USN) REFERENCES STUDENT(USN),FOREIGN KEY(SSID) REFERENCES SEM_SEC(SSID));

CREATE TABLE SUBJECT(SUBCODE VARCHAR(10) PRIMARY KEY,TITLE VARCHAR(10),SEM

INT,CREDITS INT);

Page 34: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

34 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

CREATE TABLE IA_MARKS(USN VARCHAR(15),SUBCODE VARCHAR(10),SSID INT,PRIMARY

KEY(USN,SUBCODE,SSID),TEST1 FLOAT,TEST2 FLOAT,TEST3 FLOAT,FINALIA

FLOAT,FOREIGN KEY(USN) REFERENCES STUDENT(USN),FOREIGN KEY(SUBCODE)

REFERENCES SUBJECT(SUBCODE),FOREIGN KEY(SSID) REFERENCES SEM_SEC(SSID));

Table description:

DESC STUDENT;

DESC SEM_SEC;

DESC CLASS;

DESC SUBJECT;

Page 35: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

35 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

DESC IA_MARKS;

Insertion of values to tables:

INSERT INTO STUDENT

VALUES(“1BI15CS101”,”SINISTAR”,”MALLESHWARAM”,”9988776655”,”MALE”);

INSERT INTO STUDENT VALUES(“1BI15ME121”,”DRACCU”,”MYSORE”,”8523697413”,”MALE”);

INSERT INTO STUDENT

VALUES(“4GS17CS031”,”SUSHMITHA”,”MYSORE@123”,”9632587410”,”FEMALE”);

INSER INTO STUDENT

VALUES(“4MH15IS006”,”DRUSHYA”,”MADDUR”,”7090454640”,”FEMALE”);

INSERT INTO STUDENT VALUES(“4MH17IS053”,”NISHA

GOWDA”,”MANDYA”,”9380577730”,”FEMALE”);

Page 36: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

36 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

INSERT INTO STUDENT VALUES(“5BI15EC108”,”SMILE

STAR”,”KODIYALA”,”7412589630”,”FEMALE”);

INSERT INTO SEM_SEC VALUES(“100”,”4”,”C”);

INSERT INTO SEM_SEC VALUES(“101”,”4”,”A”);

INSERT INTO SEM_SEC VALUES(“102”,”8”,’C”);

INSERT INTO SEM_SEC VALUES(“103”,”8”,”B”);

INSERT INTO SEM_SEC VALUES(“104”,”4”,”C”);

INSERT INTO SEM_SEC VALUES(“105”,”6”,”A”);

INSERT INTO SEM_SEC VALUES(“106”,”6”,”B”);

INSERT INTO SEM_SEC VALUES(“107”,”6”,”C”);

INSERT INTO SEM_SEC VALUES(“108”,”8”,”B”);

INSERT INTO SEM_SEC VALUES(“109”,”4”,”B”);

INSERT INTO CLASS VALUES(“1BI15CS101”,”100”);

INSERT INTO CLASS VALUES(“4MH17IS053”,”102”);

INSERT INTO CLASS VALUES(“1BI15ME121”,”103”);

INSERT INTO CLASS VALUES(“4GS17CS031”,”104”);

INSERT INTO CLASS VALUES(“5BI15EC108”,”105”);

INSERT INTO CLASS VALUES(“4MH15IS006”,”107”);

INSERT INTO SUBJECT VALUES(“17CS51”,”M&EFORITI”,”6”,”32”);

Page 37: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

37 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

INSERT INTO SUBJECT VALUES(“17CS52”,”CPTRNTWRKS”,”4”,”34”);

INSERT INTO SUBJECT VALUES(“17CS53”,”DBMS”,”8”,”38”);

INSERT INTO SUBJECT VALUES(“17CS54”,”ATC”,”6”,”30”);

INSERT INTO SUBJECT VALUES(“17CS551”,”OOMD”,”6”,”28”);

INSERT INTO SUBJECT VALUES(“17CS552”,”CSHARP”,”4”,”30”);

INSERT INTO IA_MARKS VALUES(“1BI15CS101”,”17CS51”,”100”,”10”,”18”,”19’,”NULL”);

INSERT INTO IA_MARKS VALUES(“1BI15CS101”,”17CS551”,”108”,”18”,”18”,”18”,”NULL”);

INSERT INTO IA_MARKS VALUES(“1BI15ME121”,”17CS552”,”107”,”15”,”12’,”12”,”NULL”);

INSERT INTO IA_MARKS VALUES(“4GS17CS031”,”17CS53”,”105”,”12’,”8”,”5”,”NULL”);

INSERT INTO IA_MARKS VALUES(“4MH15IS006”,”17CS54”,”102”,”15”,”20”,”18”);

INSERT INTO IA_MARKS VALUES(“4MH17IS053”,”17CS53”,”101”,”20”,”18’,”19”,”NULL”);

INSERT INTO IA_MARKS VALUES(“4MH17IS053”,”17CS53”,”103”,”18”,”18”,”18’,”NULL”);

SELECT * FROM STUDENT;

SELECT * FROM SEM_SEC;

Page 38: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

38 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

SELECT * FROM CLASS;

SELECT * FROM SUBJECT;

Page 39: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

39 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

SELECT * FROM IA_MARKS;

Queries:s

1. List all the student details studying in 4th sem ‘C’ section.

SELECT s. USN, SNAME, ADDRESS FROM STUDENT s, SEM_ SEC m, CLASS C WHERE s.

USN=c. USN AND m. SSID=c. SSID AND SEM=”4” AND SEC=”C”;

2. Compute the total number of male and female students in each semester and in each section.

SELECT m. SEC, m. SEC, s. GENDER, COUNT(GENDER) FROM STUDENT s, SEM_ SEC m,

CLASS c WHERE s. USN=c. USN AND m. SSID=c. SSID GROUP BY m. SEM, m. SEC, s.

GENDER ORDER BY SEM;

Page 40: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

40 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

3. Create a view of tset1 marks of student USN,1bi15cs101 in all subjects.

CREATE VIEW S1 AS(SELECT TEST1,SUBCODE FROM IA_MARKS WHERE

USN=”1BI15CS101”);

SELECT * FROM S1;

4. Calculate the FinalIA(average of best two test marks) and update corresponding table for all

students.

UPDATE IA_MARKS SET

FINALIA=GREATEST(TEST1+TEST2,TEST2+TEST3,TEST1+TEST3)/2;

OR

UPDATE IA_MARKS SET FINALIA=((TEST1+TEST2+TEST3)-

LEAST(TEST1,TEST2,TEST3))/2;

Page 41: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

41 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

5. Catagarize the students based on the following criterian : If Final IA=17 to 20 then

CAT=’Outstanding’

If Final IA=12 to 16 the CAT=’Average’

If Final IA<12 the CAT=’Weak’.

Give the details only for 8th sem ‘A’,’B’ and ‘C’ sec.

SELECT s. USN, SNAME,ADDRESS,GENDER,(CASE WHEN FINALIA BETWEEN 17 AND

20 THEN “OUTSTANDING” WHEN FINALIA BETWEEN 12 AND 16 THEN “AVERAGE”

ELSE “WEAK” END) AS CAT FROM STUDENT s, IA_MARKS I,SUBJECT b, SEM_SEC m

WHERE s. USN=i. USN AND m. SSID=i. SSID AND b. SUBCODE=i. SUBCODE AND m.

SEM=”8” AND m. SEC IN(“A”,”B”,”C”);

6. Consider the schema for Company Database:

EMPLOYEE(SSN, Name, Address, Sex, Salary, SuperSSN, Dno)

DEPARTMENT(Dno, Dname, MgrSSN, MgrstartDate)

DLOACTION(Dno, Dloc)

PROJECT(Pno, Pname, Ploaction, Dno)

WORKS_ON(SSN, Pno, Hours)

Page 42: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

42 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Write SQL queries to

1. Make a list of all project numbers for projects that involve an employee whose last name is

‘Scott’, either as a worker or as number of the department that controls the project.

2. Show the resulting salaries if every employee working on the ‘IOT’ project is given a 10

percent raise.

3. Find the sum of the salaries of all employees of the ‘accounts’ department, as well as the

maximum salary, the minimum salary, and the average salary in this department.

4. Retrieve the name of each employee who works on all the operation Projects controlled by

department number 5 (use NOT EXITS operation).

5. For each department that has more than five employees. Retrieve the department number

and the number of its employees who are making more than Rs 6,00,000

Solution:

Page 43: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

43 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Schema diagram:

EMPLOYEE

SSN fname lname address sex salary superSSn dno

DEPARTMENT

dno dname mgrSSN mgrstartdate

DLOCATION

dno dloc

PROJECT

pno pname plocation dno

WORKSON

SSN pno hours

TABLE CREATION

CREATE TABLE EMPLOYEE(SSN INT PRIMARY KEY,FNAME CHAR(10),LNAME

CHAR(10),ADDRESS VARCHAR(15),SEX CHAR(6),SALARY REAL,SUPERSSN INT,DNO INT);

CREATE TABLE DEPARTMENT(DNO INT PRIMARY KEY,DNAME CHAR(15),MGRSSN

INT,MGERSTART DATE);

CREATE TABLE DLOACTION(DNO INT,DLOC CHAR(10),PRIMARY KEY(DNO,DLOC),FOREIGN

KEY(DNO) REFERENCES DEPARTMENT(DNO));

Page 44: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

44 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

CREATE TABLE PROJECT(PNO INT PRIMARY KEY,PNAME CHAR(15),PLOACTION

CHAR(10),DNO INT,FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));

CREATE TABLE WORKS_ON(SSN INT,PNO INT,PRIMARY KEY(SSN,PNO),FOREIGN KEY(SSN)

REFERENCES EMPLOYEE(SSN),FOREIGN KEY(PNO) REFERENCES PROJECT(PNO),HOURS

INT);

Table description:

DESC EMPLOYEE;

DESC DEPARTMENT;

DESC DLOCATION;

Page 45: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

45 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

DESC PROJECT;

DESC WORKS_ON;

ALTERING COMMANDS

ALTER TABLE EMPLOYEE ADD CONSTRAINT S FOREIGN KEY(DNO) REFERENCES

DEPARTMENT(DNO);

ALTER TABLE DEPARTMENT ADD CONSTRAINT R FOREIGN KEY(MGRSSN) REFERENCES

EMPLOYEE(SSN);

DESC EMPLOYEE;

Page 46: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

46 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

DESC DEPARTMENT;

INSERT ION OF VALUES TO TABLES

INSERT INTO EMPLOYEE

VALUES(“100”,”WATTSON”,”SCOTT”,”MYSORE12”,”MALE”,”750000”,”100”,”1”);

INSERT INTO EMPLOYEE

VALUES(“101”,”MARRY”,”STEVE”,”MYSORE123”,”FEMALE”,”850000”,”100”,”1”);

INSERT INTO EMPLOYEE

VALUES(“102”,”STEVE”,”JOBS”,”BANGLORE123”,”MALE”,”800000”,”101”,”5”);

INSERT INTO EMPLOYEE

VALUES(“103”,”RED”,”KANE”,”BANGLORE13”,”MALE”,”900000”,”5”);

Page 47: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

47 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

INSERT INTO EMPLOYEE

VALUES(“104”,”JOHN”,”CENA”,”BANGLORE25”,”MALE”,”950000”,”100”,”1”);

INSERT INTO EMPLOYEE

VALUES(“105”,”BLOCK”,”LUSTER”,”BANGLORE15”,”FEMALE”,”750000”,”100”,”1”);

INSERT INTO EMPLOYEE VALUES(“106”,”KALI”,”SHOW”,”INDIA”,”MALE”,”850000”,”102”,”1”);

INSERT INTO EMPLOYEE

VALUES(“107”,”RUSEV”,”LENSER”,”RUSSIA”,”MALE”,”800000”,”100”,”1”);

INSERT INTO EMPLOYEE

VALUES(“108”,”WATTSON”,”SCOTT”,”MYSORE12”,”MALE”,”750000”,”100”,”1”);

IINSERT INTO DEPARTMENT VALUES(“1”,”ACCOUNTS”,”100”,”1999/01/03”);

INSERT INTO DEPARTMENT VAULES(“2”,”HOLDER”,”102”,”1989/02/24”);

INSERT INTO DEPARTMENT VALUES(“3”,”BALANCE”,”101”,”1982/07/17”);

INSERT INTO DEPARTMENT VALUES(“4”,”ACNTMAKR”,”100”,”1991/12/24”);

INSERT INTO DEPARTMENT VALUES(“5”,”SCHLORSHP”,”101”,”2000/07/17”);

INSERT INTO DLOACTION VALUES(“1”,”GRNDFLR”);

INSERT INTO DLOCATION VALUES(“1”,”TOPFLR”);

INSERT INTO DLOCATION VALUES(“3”,”HYRIGE”);

INSERT INTO DLOCATION VALUES(“4”,MYSORE”);

INSERT INTO DLOCATION VALUES(“5”,”MANDYA”);

INSERT INTO PROJECT VALUES(“1001”,”IOT”,”MYS”,”1”);

Page 48: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

48 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

INSERT INTO PROJECT VALUES(“1002”,”L&T”,”BAN”,”2”);

INSERT INTO PROJECT VALUES(“1003”,”MED”,”MAN”,”1”);

INSERT INTO PROJECT VALUES(“1004”,”CPG”,”SOUTH”,”5”);

INSERT INTO PROJECT VALUES(“1005”,”VIP”,”NORTH”,”5”);

INSERT INTO PROJECT VALUES(“1006”,”INF”,”WEST”,”3”);

INSERT INTO WORKSON VALUES(“100”,”1001”,”2”);

INSERT INTO WORKSON VALUES(“100”,”1002”,”3”);

INSERT INTO WORKSON VALUES(“101”,”1003”,”3”);

INSERT INTO WORKSON VALUES(“107”,”1004”,”1”);

INSERT INTO WORKSON VALUES(“107”,”1005”,”4”);

INSERT INTO WORKSON VALUES(“107”,”1006”,”3”);

SELECT * FROM EMPLOYEE;

SELECT * FROM DEPARTMENT;

Page 49: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

49 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

SELECT * FROM DLOCATION;

SELECT * FROM PROJECT;

SELECT * FROM WORKSON;

Page 50: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

50 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Queries:

1. make a list of all projects numbers for projects that involve an employee whose last name is ‘scott’,

either as a worker or as a manager of the department that controller project.

(SELECT PNO FROM EMPLOYEE e, WORKSON w WHERE e.SSN=w.SSN AND LNAME=”SCOTT”) UNION

(SELECT PNO FROM DEPARTMENT d, PROJECT p, EMPLOYEE e WHERE SSN=MGRSSN AND d.DNO=p.DNO

AND LNAME=”SCOTT”);

2. Show the resulting salaries if every employee working on the ‘IOT’ project is given a 10 percent

raise.

SELECT SALARY*1.1 FROM EMPLOYEE e, PROJECT p, WORKSON w WHERE e.SSN=w.SSN AND

p.PNO=w.PNO AND PNAME=”IOT”;

3. Find the sum of the salaries of all employees of the ‘Accounts’ department, as well as the maximum

salary, the minimum salary, and the average salary in this department.

Page 51: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

51 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

SELECT SUM(SALARY),MAX(SALARY),MIN(SALARY),AVG(SALARY) FROM EMPLOYEE e,

DEPARTMENT d WHERE e.DNO=d.DNO AND DNAME=”ACCOUNTS”;

4. Retrieve the name of each employee who workers on all the projects controlled by department

number 5 (use NOT EXIST operator).

SELECT FNAME, LNAME FROM EMPLOYEE e WHERE NOT EXISTS(SELECT PNO FROM

PROJECT WHERE DNO=5 AND PNO NOT IN(SELECT PNO FROM WORKSON WHERE e.

SSN=SSN));

5. For each department that has more than five employees, retrieve the department number and the

number of its employees who are making more than Rs.6,00,000.

SELECT d. DNO, COUNT(*) FROM DEPARTMENT d, EMPLOYEE e WHERE d. DNO=e. DNO AND

SALARY=6,00,000 AND d. DNO IN(SELECT e1.DNO FROM EMPLOYEE e1 GROUP BY e1.DNO

HAVING COUNT(*)>5) GROUP BY d.DNO;

Page 52: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

52 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

ADDITIONAL EXERCISES ON DATABASE APPLICATION LABORATORY

Exercise 1:

To understand some simple Database Applications and build Conceptual Data Model.

a) Select an enterprise that you are familiar with (for example, a school, a college, a company, a

small business, a club or association). List all the information that this enterprise uses.

b) Describe the steps involved in the database design process using E-R Modeling: Requirements

Analysis, Identify Entity Sets, Identify Relationship Sets, Value Sets and Attributes, Specifying

Primary keys, Building E-R diagram, Implementation

c) For the following mini-world example database applications, Design and Develop Conceptual

Data Model (E-R Diagram) with all the necessary entities, attributes, constraints and relationships.

i. Medical Clinic Database – The clinic has a number of regular patients and new patients come to

the clinic regularly. Patients make appointments to see one of the doctors; several doctors attend the

clinic and they each have their own hours. Some doctors are General Practitioners (GPs) while

others are specialists(cardiologists, dermatologists etc.,). Patients have families and the family

relationships are important. A medical record of each patient needs to be maintained. Information

on prescriptions, insurance, allergies, etc needs to be maintained. Different doctors may charge

different fees. Billing has to be done for Patients.

ii. University Database - The Visvesvaraya Technological University (VTU) is a large Institution

with several campuses scattered across Karnataka. Academically, the university is divided into a

number of faculties, such as Faculty of Engineering, Faculty of Architecture, Faculty of

Management and Faculty of Science. Some of the Faculties operate on a number of campuses.

Faculties, in turn, are divided into schools; for example, the School of Architecture, the School of

Information Technology. Each school is headed by a Director and has a number of teaching and

non-teaching staff. Each school offers many courses. Each course consists of a fixed core of subjects

and a number of electives from other courses. Each student in the University is enrolled in a single

course of study. A subject is taught to the students

who have registered for that subject by a teacher. A student is awarded a grade in each subject taken.

iii. Construction Company Database - A construction company has many branches spread all

over the country. The company has two types of constructions to offer: Housing and Commercial.

The housing company provides low-income housing, medium-style housing, and high-end housing

schemes, while commercial side, it offers multiplexes and shopping zones. The customers of the

company may be individuals or corporate clients. Company stores the information about

employees‘ works for it.

iv. Time Table Preparation - An Engineering College has a number of Branches. Each Branch has

number sections, a number of courses and a number of faculty members teaching the courses. Each

branch has a number of class rooms and laboratories. Each course may be scheduled in a class room

at a particular time.

Note: Similar applications may be explored and given as assignments to students in a group.

Exercise 2: Design and build Relational Data Model for each of the application scenarios of

exercise 1 specifying all possible constraints. Extend the same for a database application of students'

choice.

Page 53: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

53 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Exercise 3 To understand and demonstrate DDL, DML and DCL Commands of SQL

a. Create a table called EMP with the following structure and describe it.

Name Type

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

EMPNO NUMBER (6)

ENAME VARCHAR2 (20)

DOB DATE

JOB VARCHAR2 (10)

DEPTNO NUMBER (2)

SAL NUMBER (7,2)

Allow NULL for all columns except ENAME and JOB. EMPNO is the Primary Key

b. Add a column EXPERIENCE of type NUMERIC to the EMP table. Allow NULL to it.

c. Modify the column width of the JOB field of EMP table.

d. Create DEPT table with the following structure and describe it

Name Type

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

DEPTNO NUMBER (2)

DNAME VARCHAR2 (15)

LOCN VARCHAR2 (10)

DEPTNO is the Primary Key and DNAME cannot be NULL

e. Add constraint to check the SAL value of EMP Table. SAL must be > 6000.

f. Drop a column EXPERIENCE from the EMP table.

g. Insert a single record into DEPT table. Repeat this for inserting at least 3 records

h. Insert more than a record into EMP table using a single insert command. Insert at least 10 records

i. Update the EMP table to set the salary of all employees to Rs. 30000/- for a given JOB type

j. Create a pseudo table EMPLOYEE with the same structure as the table EMP using SELECT

clause.

k. Delete employees from EMP table for a given JOB type. Delete the first five records of EMP

table

l. Grant all/some privileges of EMP table to DEPT table

m. Revoke some/all privileges of EMP table from DEPT table

n. Truncate the EMP table and drop the DEPT table

o. Demonstrate the use of COMMIT, SAVEPOINT and ROLLBACK commands

Page 54: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

54 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Viva Questions:

1. What is SQL?

Structured Query Language.

2. What is database?

A database is a logically coherent collection of data with some inherent meaning, representing some

aspects of real world and which is designed, built and populated with data for a specific purpose.

3. What is DBMS?

It is a collection of programs that enables the users to create and maintain a database. In other words

it is general-purpose software that provides the users with the processes of defining, constructing

and manipulating the database for various applications.

4. What is database system?

The database and DBMS software together is called as Database system.

5. Advantages of DBMS?

Redundancy is controlled.

Unauthorized access is restricted.

Providing multiple user interfaces.

Enforcing integrity constraints.

Providing backup and recovery.

6. Disadvantages in file Processing System?

Data redundancy and inconsistency.

Difficult in accessing data.

Data integrity.

Concurrent access is not possible.

Security problems.

7. Describe the three levels of data abstraction?

There are three levels of abstraction:

Physical level: the lowest level of abstraction describes how data are stored.

Logical level: the next higher level of abstraction, describes what data are stored in database

and what relationship among those data.

View level: the highest level of abstraction describes only part of entire database.

8. Define the “Integrity” rules.

There are two integrity rules:

Entity Integrity: States that- primary key cannot be NULL value.

Referential Integrity: States that- Foreign key can be either a NULL value or should be

Page 55: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

55 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

Primary key value of other relation.

9. What is extension and intension?

Extension – It is the number of tuples present in a table at any instance. This is a time dependent.

Intension – It is a constant value that gives the name, Structure of the table and the constraints laid

on it.

10. What is data independence?

Data independence means that – the application is independent of the storage structure and access

strategy of data. In other words, the ability to modify the schema definition in one level should not

affect the schema definition in the next higher level.

Two types of Data Independence.

Physical Data Independence: Modification in physical level should not affect the logical

level.

Logical Data Independence: Modification in logical level should affect the view level.

NOTE: Logical Data Independence is more difficult to achieve.

11. What is a view? How it is related to data independence?

A view may be thought of as a virtual table, that is, a table that does not really exist in its own right

but is instead derived from one or more underlying base table. In other words, there is no stored file

that direct represents the view instead a definition of view is stored in data dictionary.

Growth and restructuring of base tables in not reflected in views. Thus the view can insulate

users from the effects of restructuring and growth in the database. Hence accounts for logical data

independence.

12. What is Data model?

A collection of conceptual tools for describing data, data relationships data semantic and constraints.

13. What is E-R model?

This data model is based on real world that consists of basic objects called entities and of relationship

among these objects. Entities are described in a database by a set of attributes.

14. What is object oriented model?

This model is based on collection of objects. An object contains values stored in instance variables

within the object. An object also contains bodies of code that operate on the object. These bodies of

code are called methods. Objects that contain same types of values and the same methods are grouped

together into classes.

15. What is an Entity?

It is an ‘object’ in the real world with an independent existence.

16. What is an Entity type?

Page 56: DBMS LABORATORY WITH MINI PROJECT · lab manual for v semester maharaja institute of technology, mysore department of information science & engineering mit mysore . 2 department of

56 DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING 2019

DBMS LABORATORY WITH MINI PROJECT 17CSL58

It is a collection (set) of entities that have same attributes.

17. What is an Entity set?

It is a collection of all entities of particular entity type in the database.

18. What is an Extension of entity type?

The collection of entities of a particular entity type are grouped together into an entity set.

19. What is an attribute?

It is a particular property, which describes the entity.

20. What is a Relation Schema and a Relation?

A Relation Schema denoted by R (A1, A2, …..., An) is made up of the relation name R and the list

of attributes Ai that it contains. A relation is defined as a set of tuples. Let R be the relation which

contains set tuples ( t1, t2, t3, ….., tn). Each tuple is an ordered list of n-values t=(v1, v2,

……, vn).

21. What is degree of a relation?

It is an number of attribute of its relation schema.

22. What is Relationship?

It is an association among two or more entities.

23. What is Relationship set?

The collection (or set) of similar relationship.

24. What is Relationship type?

Relationship type defines a set of associations or a relationship set among a given set of entity types.

25. What is degree of Relationship type?

It is the number of entity type participating.

26. What is DDL (Data Definition Language)?

A data base schema is specified by a set of definitions expressed by a special language called DDL.

27. What is VDL (View Definition Language)?

It specifies user views and their mapping to the conceptual schema.

28. What is SDL (Storage Definition Language)?

This language is to specify the internal schema. This language may specify the mapping between

two schemas.

29. What is Data storage- Definition Language?

The storage structures and access methods used by database system are specified by a set of

definition in a special type of DDL called Data storage – definition language.