@vtucode - in 2021 Scheme DBMS Lab Malual 5th Semester
@vtucode - in 2021 Scheme DBMS Lab Malual 5th Semester
CREDITS 01
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.
Lab Experiments:
Part A: SQL Programming
Give these details only for 8th semester A, B, and C section student
5. Consider the schema for Company Database:
EMPLOYEE (SSN, Name, Address, Sex, Salary, SuperSSN, DNo)
DEPARTMENT (DNo, DName, MgrSSN, MgrStartDate)
DLOCATION (DNo, DLoc)
PROJECT (PNo, PName, PLocation, DNo)
WORKS_ON( SSN, PNo, Hours)
Write SQL queries to
1. Make a list of all project numbers for projects that involve an employee whose last
name is either as a worker or as a manager of the department that controls the
project.
2. Show the resulting salaries if is given a
10 percent raise.
3. Find the sum of the salaries of all employees of the 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 projects controlled by
department number 5 (use NOT EXISTS operator).
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.
Experiment distribution
1. For laboratories having only one part: Students are allowed to pick one experiment from
the lot with equal opportunity.
2. For laboratories having PART A and PART B: Students are allowed to pick one
experiment from PART A and one experiment from PART B, with equal opportunity.
3. Change of experiment is allowed only once and marks allotted for procedure to be made
zero of the changed part only.
4. Marks Distribution (Coursed to change in accordance with university regulations)
Program 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.
vtucode.in Page 01
DBMS Laboratory with mini Project 21CSL55
Solution:
Entity-Relationship Diagram
vtucode.in Page 02
DBMS Laboratory with mini Project 21CSL55
Schema Diagram
vtucode.in Page 03
DBMS Laboratory with mini Project 21CSL55
Table Creation
vtucode.in Page 04
DBMS Laboratory with mini Project 21CSL55
CREATE TABLE LIBRARY_PROGRAMME (
PROGRAMME_ID INT (10) PRIMARY KEY,
PROGRAMME_NAME VARCHAR (50),
ADDRESS VARCHAR (100));
Table Descriptions
DESC BOOK
;
DESC BOOK_AUTHORS;
DESC PUBLISHER;
DESC BOOK_COPIES
vtucode.in Page 05
DBMS Laboratory with mini Project 21CSL55
DESC BOOK_LENDING;
DESC CARD;
DESC LIBRARY_PROGRAMME
vtucode.in Page 06
DBMS Laboratory with mini Project 21CSL55
Insertion of Values to Tables
vtucode.in Page 07
DBMS Laboratory with mini Project 21CSL55
SELECT * FROM BOOK;
AUTHOR_NAME BOOK_ID
NAVATHE 1
NAVATHE 2
ULLMAN 3
CHARLES 4
GALVIN 5
vtucode.in Page 08
DBMS Laboratory with mini Project 21CSL55
CARDNO
101
102
103
104
105
vtucode.in Page 09
DBMS Laboratory with mini Project 21CSL55
Queries:
1. Retrieve details of all books in the library id, title, name of publisher, authors, number
of copies in each branch, etc.
SELECT B.BOOK_ID, B.TITLE, B.PUBLISHER_NAME, A.AUTHOR_NAME,
C.NO_OF_COPIES, L.PROGRAMME_ID FROM BOOK B, BOOK_AUTHORS A, BOOK_COPIES
C, LIBRARY_PROGRAMME L WHERE B.BOOK_ID=A.BOOK_ID AND
B.BOOK_ID=C.BOOK_ID AND L.PROGRAMME_ID=C.PROGRAMME_ID;
2. Get the particulars of borrowers who have borrowed more than 3 books, but from Jan
2017 to Jun 2017.
SELECT CARD_NO FROM BOOK_LENDING WHERE DATE_OUT
BETWEEN '2017-01-01'AND '2017-07-01' GROUP BY CARD_NO
HAVING COUNT(*)>3;
vtucode.in Page 10
DBMS Laboratory with mini Project 21CSL55
3. Delete a book in BOOK table. Update the contents of other tables to reflect this data
manipulation operation.
4. Partition the BOOK table based on year of publication. Demonstrate its working with a
simple query.
5. Create a view of all books and its number of copies that are currently available in the
Library.
CREATE VIEW VW_BOOKS AS SELECT B.BOOK_ID, B.TITLE, C.NO_OF_COPIES
FROM BOOK B, BOOK_COPIES C, LIBRARY_PROGRAMME L WHERE
B.BOOK_ID=C.BOOK_ID AND C.PROGRAMME_ID=L.PROGRAMME_ID;
vtucode.in Page 11
DBMS Laboratory with mini Project 21CSL55
SELECT * FROM VW_BOOKS;
Program Outcomes:
The students are able to
Create, Update and query on the database.
Demonstrate the working of different concepts of DBMS
Implement, analyze and evaluate the project developed for an application.
vtucode.in Page 12
DBMS Laboratory with mini Project 21CSL55
B. Consider the following schema for Order Database:
SALESMAN (Salesman_id, Name, City, Commission)
CUSTOMER (Customer_id, Cust_Name, City, Grade, Salesman_id)
ORDERS (Ord_No, Purchase_Amt, Ord_Date, Customer_id, Salesman_id)
Program 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.
Solution:
Entity-Relationship Diagram
vtucode.in Page 13
DBMS Laboratory with mini Project 21CSL55
Schema Diagram
Table Creation
vtucode.in Page 14
DBMS Laboratory with mini Project 21CSL55
Table Descriptions
DESC SALESMAN;
DESC CUSTOMER;
DESC ORDERS;
Insertion of Value
vtucode.in Page 15
DBMS Laboratory with mini Project 21CSL55
vtucode.in Page 16
DBMS Laboratory with mini Project 21CSL55
Queries
1. average.
SELECT GRADE, COUNT (CUSTOMER_ID) FROM
CUSTOMER GROUP BY GRADE
HAVING GRADE > (SELECT AVG (GRADE) FROM
CUSTOMER WHERE CITY='BANGALORE');
2. Find the name and numbers of all salesmen who had more than one customer.
SELECT SALESMAN_ID,NAME
FROM SALESMAN A
WHERE 1 <(SELECT COUNT(*) FROM CUSTOMER
WHERE SALESMAN_ID=A.SALESMAN_ID)
OR
SELECT S.SALESMAN_ID,NAME, FROM CUSTOMER
C,SALESMAN S WHERE
S.SALESMAN_ID=C.SALESMAN_ID GROUP BY
C.SALESMAN_ID HAVING COUNT(*)>1
3. their cities
(Use UNION operation.)
vtucode.in Page 17
DBMS Laboratory with mini Project 21CSL55
4. Create a view that finds the salesman who has the customer with the highest order of a
day.
CREATE VIEW VW_ELITSALESMAN AS
SELECT B.ORD_DATE,A.SALESMAN_ID,A.NAME FROM SALESMAN A, ORDERS B
WHERE A.SALESMAN_ID = B.SALESMAN_ID AND B.PURCHASE_AMT=(SELECT
MAX(PURCHASE_AMT) FROM ORDERS C
WHERE C.ORD_DATE = B.ORD_DATE);
5. Demonstrate the DELETE operation by removing salesman with id 1000. All his orders
must also be deleted.
Use ON DELETE CASCADE at the end of foreign key definitions while creating child table
orders and then execute the following:
vtucode.in Page 18
DBMS Laboratory with mini Project 21CSL55
Program 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.
Solution:
Entity-Relationship Diagram
vtucode.in Page 19
DBMS Laboratory with mini Project 21CSL55
Schema Diagram
Table Creation
CREATE TABLE ACTOR (
ACT_ID INT (5) PRIMARY KEY,
ACT_NAME VARCHAR (20),
ACT_GENDER CHAR (1));
vtucode.in Page 20
DBMS Laboratory with mini Project 21CSL55
CREATE TABLE RATING (
MOV_ID INT (5) PRIMARY KEY,
REV_STARS VARCHAR (25),
FOREIGN KEY (MOV_ID) REFERENCES MOVIES (MOV_ID));
Table Descriptions
DESC ACTOR;
DESC DIRECTOR;
DESC MOVIES;
DESC MOVIES_CAST;
vtucode.in Page 21
DBMS Laboratory with mini Project 21CSL55
DESC RATING;
9563400156);
INSERT INTO DIRECTOR VALUES(102,'ALAN TAYLOR',9971960035);
25);
75);
INSERT INTO DIRECTOR VALUES (105,'HITCHCOCK',7766138911);
INSERT INTO DIRECTOR VALUES (106,'STEVEN SPIELBERG',9966138934);
vtucode.in Page 22
DBMS Laboratory with mini Project 21CSL55
SELECT * FROM ACTOR;
vtucode.in Page 23
DBMS Laboratory with mini Project 21CSL55
MOV_ID REV_STARS
501 4
502 2
503 5
504 4
505 3
506 2
507 2
508 4
vtucode.in Page 24
DBMS Laboratory with mini Project 21CSL55
Queries:
1. List the titles of all movies directed by
SELECT MOV_TITLE FROM MOVIES WHERE DIR_ID IN (SELECT DIR_ID FROM
OR
SELECT MOV_TITLE FROM MOVIES M, DIRECTOR D WHERE M.DIR_ID=D.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,MOVIES_CAST MV
WHERE M.MOV_ID=MV.MOV_ID AND ACT_ID IN(SELECT ACT_ID FROM
MOVIES_CAST GROUP BY ACT_ID HAVING COUNT(ACT_ID)>1) GROUP BY
MOV_TITLE HAVING COUNT(*)>1;
3. List all actors who acted in a movie before 2000 and also in a movie after 2015 (use JOIN
operation).
SELECT ACT_NAME, MOV_TITLE, MOV_YEAR FROM ACTOR A JOIN
MOVIE_CAST C ON A.ACT_ID=C.ACT_ID INNER JOIN MOVIES M
ON C.MOV_ID=M.MOV_ID WHERE M.MOV_YEAR NOT BETWEEN 2000 AND 2015;
vtucode.in Page 25
DBMS Laboratory with mini Project 21CSL55
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.
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. 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'));
OR
UPDATE RATING R, MOVIES M, DIRECTOR D SET REV_STARS=5 WHERE
R.MOV_ID=M.MOV_ID AND M.DIR_ID=D.DIR_ID AND DIR_NAME='STEVEN
SPIELBERG';
Program Outcomes:
The students are able to
Create, Update and query on the database.
Demonstrate the working of different concepts of DBMS
Implement, analyze and evaluate the project developed for an application.
vtucode.in Page 26
DBMS Laboratory with mini Project 21CSL55
D. Consider the schema for College Database:
STUDENT (USN, SName, Address, Phone, Gender)
SEMSEC (SSID, Sem, Sec)
CLASS (USN, SSID)
SUBJECT (Subcode, Title, Sem, Credits)
IAMARKS (USN, Subcode, SSID, Test1, Test2, Test3, FinalIA)
Give these details only for 8th semester A, B, and C section students.
Program 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.
Solution:
Entity - Relationship Diagram
vtucode.in Page 27
DBMS Laboratory with mini Project 21CSL55
Schema Diagram
Table Creation
CREATE TABLE STUDENT (
USN VARCHAR (10) PRIMARY KEY,
SNAME VARCHAR (25),
ADDRESS VARCHAR (25),
PHONE BIGINT (10),
GENDER CHAR (1));
vtucode.in Page 28
DBMS Laboratory with mini Project 21CSL55
CREATE TABLE IAMARKS (
USN VARCHAR (10),
SUBCODE VARCHAR (8),
SSID VARCHAR (5),
TEST1 INT (2),
TEST2 INT (2),
TEST3 INT (2),
FINALIA INT (2),
PRIMARY KEY (USN, SUBCODE, SSID),
FOREIGN KEY (USN) REFERENCES STUDENT (USN),
FOREIGN KEY (SUBCODE) REFERENCES SUBJECT (SUBCODE), FOREIGN
KEY (SSID) REFERENCES SEMSEC (SSID));
Table Descriptions
DESC STUDENT;
DESC SEMSEC;
DESC CLASS;
vtucode.in Page 29
DBMS Laboratory with mini Project 21CSL55
DESC SUBJECT;
DESC IAMARKS;
vtucode.in Page 30
DBMS Laboratory with mini Project 21CSL55
INSERT INTO SEMSEC VALUES ('CSE8A', 8,'A');
INSERT INTO SEMSEC VALUES ('CSE8B', 8,'B');
INSERT INTO SEMSEC VALUES ('CSE8C', 8,'C');
INSERT INTO SEMSEC VALUES ('CSE7A', 7,'A');
INSERT INTO SEMSEC VALUES ('CSE7B', 7,'B');
INSERT INTO SEMSEC VALUES ('CSE7C', 7,'C');
INSERT INTO SEMSEC VALUES ('CSE6A', 6,'A');
INSERT INTO SEMSEC VALUES ('CSE6B', 6,'B');
INSERT INTO SEMSEC VALUES ('CSE6C', 6,'C');
INSERT INTO SEMSEC VALUES ('CSE5A', 5,'A');
INSERT INTO SEMSEC VALUES ('CSE5B', 5,'B');
INSERT INTO SEMSEC VALUES ('CSE5C', 5,'C');
INSERT INTO SEMSEC VALUES ('CSE4A', 4,'A');
INSERT INTO SEMSEC VALUES ('CSE4B', 4,'B');
INSERT INTO SEMSEC VALUES ('CSE4C', 4,'C');
INSERT INTO SEMSEC VALUES ('CSE3A', 3,'A');
INSERT INTO SEMSEC VALUES ('CSE3B', 3,'B');
INSERT INTO SEMSEC VALUES ('CSE3C', 3,'C');
INSERT INTO SEMSEC VALUES ('CSE2A', 2,'A');
INSERT INTO SEMSEC VALUES ('CSE2B', 2,'B');
INSERT INTO SEMSEC VALUES ('CSE2C', 2,'C');
INSERT INTO SEMSEC VALUES ('CSE1A', 1,'A');
INSERT INTO SEMSEC VALUES ('CSE1B', 1,'B');
INSERT INTO SEMSEC VALUES ('CSE1C', 1,'C');
vtucode.in Page 31
DBMS Laboratory with mini Project 21CSL55
INSERT INTO SUBJECT VALUES ('10CS72','ECS', 7, 4);
INSERT INTO SUBJECT VALUES ('10CS73','PTW', 7, 4);
INSERT INTO SUBJECT VALUES ('10CS74','DWDM', 7, 4); I
INSERT INTO SUBJECT VALUES ('10CS75','JAVA', 7, 4);
INSERT INTO SUBJECT VALUES ('10CS76','SAN', 7, 4);
INSERT INTO SUBJECT VALUES ('15CS51', 'ME', 5, 4);
INSERT INTO SUBJECT VALUES ('15CS52','CN', 5, 4);
INSERT INTO SUBJECT VALUES ('15CS53','DBMS', 5, 4);
INSERT INTO SUBJECT VALUES ('15CS54','ATC', 5, 4);
INSERT INTO SUBJECT VALUES ('15CS55','JAVA', 5, 3);
INSERT INTO SUBJECT VALUES ('15CS56','AI', 5, 3);
INSERT INTO SUBJECT VALUES ('15CS41','M4', 4, 4);
INSERT INTO SUBJECT VALUES ('15CS42','SE', 4, 4);
INSERT INTO SUBJECT VALUES ('15CS43','DAA', 4, 4);
INSERT INTO SUBJECT VALUES ('15CS44','MPMC', 4, 4);
INSERT INTO SUBJECT VALUES ('15CS45','OOC', 4, 3);
INSERT INTO SUBJECT VALUES ('15CS46','DC', 4, 3);
INSERT INTO SUBJECT VALUES ('15CS31','M3', 3, 4);
INSERT INTO SUBJECT VALUES ('15CS32','ADE', 3, 4);
INSERT INTO SUBJECT VALUES ('15CS33','DSA', 3, 4);
INSERT INTO SUBJECT VALUES ('15CS34','CO', 3, 4);
INSERT INTO SUBJECT VALUES ('15CS35','USP', 3, 3);
INSERT INTO SUBJECT VALUES ('15CS36','DMS', 3, 3);
SELECT * FROM
vtucode.in Page 32
DBMS Laboratory with mini Project 21CSL55
SELECT * FROM SEMSEC;
vtucode.in Page 33
DBMS Laboratory with mini Project 21CSL55
vtucode.in Page 34
DBMS Laboratory with mini Project 21CSL55
Queries:
1. section.
SELECT S.*, SS.SEM, SS.SEC FROM STUDENT S, SEMSEC SS, CLASS C WHERE
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 (S.GENDER) AS COUNT FROM
STUDENT S, SEMSEC SS, CLASS C
WHERE S.USN = C.USN AND SS.SSID = C.SSID
GROUP BY SS.SEM, SS.SEC, S.GENDER ORDER BY SEM;
3. subjects.
CREATE VIEW VW_STUDENT_TEST AS SELECT TEST1,SUBCODE FROM
IAMARKS WHERE USN= 4AD13CS091';
vtucode.in Page 35
DBMS Laboratory with mini Project 21CSL55
4. Calculate the FinalIA (average of best two test marks) and update the corresponding
table for all students.
UPDATE IAMARKS
SET FINALIA=GREATEST(TEST1+TEST2,TEST2+TEST3,TEST1+TEST3)/2;
Note: Before execution above SQL statement, IAMARKS table contents are:
UPDATE IAMARKS
SET FINALIA=GREATEST(TEST1+TEST2,TEST2+TEST3,TEST1+TEST3)/2;
Give these details only for 8th semester A, B, and C section students.
SELECT S.USN,S.SNAME,S.ADDRESS,S.PHONE,S.GENDER,
(CASE
WHEN IA.FINALIA BETWEEN 17 AND 20 THEN 'OUTSTANDING'
WHEN IA. FINALIA BETWEEN 12 AND 16 THEN 'AVERAGE'
ELSE 'WEAK'
END) AS CAT
FROM STUDENT S, SEMSEC SS, IAMARKS IA, SUBJECT SUB WHERE S.USN = IA.USN
AND SS.SSID = IA.SSID AND SUB.SUBCODE = IA.SUBCODE AND SUB.SEM = 8;
vtucode.in Page 36
DBMS Laboratory with mini Project 21CSL55
Program Outcomes:
The students are able to
Create, Update and query on the database.
Demonstrate the working of different concepts of DBMS
Implement, analyze and evaluate the project developed for an application.
vtucode.in Page 37
DBMS Laboratory with mini Project 21CSL55
E.Consider the schema for Company Database:
EMPLOYEE (SSN, Name, Address, Sex, Salary, SuperSSN,
DNo) DEPARTMENT (DNo, DName, MgrSSN, MgrStartDate)
DLOCATION (DNo,DLoc)
PROJECT (PNo, PName, PLocation, DNo)
WORKS_ON (SSN, PNo, Hours)
Write SQL queries to
1. Make a list of all project numbers for projects that involve an employee whose last
project.
2. Show the resulting salaries if every employee
percent raise.
3.
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 projects controlled by
department number 5 (use NOT EXISTS operator).
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.
Program 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.
Solution:
Entity-Relationship Diagram
vtucode.in Page 38
DBMS Laboratory with mini Project 21CSL55
Schema Diagram
Table Creation
NOTE: Once DEPARTMENT and EMPLOYEE tables are created we must alter department
table to add foreign constraint MGRSSN using sql command
ALTER TABLE DEPARTMENT ADD FOREIGN KEY(MGRSSN) REFERENCES
EMPLOYEE(SSN);
vtucode.in Page 39
DBMS Laboratory with mini Project 21CSL55
CREATE TABLE DLOCATION (
DLOC VARCHAR (20),
DNO VARCHAR (20),
PRIMARY KEY (DNO, DLOC),
FOREIGN KEY (DNO) REFERENCES DEPARTMENT (DNO));
Table Descriptions
DESC EMPLOYEE;
DESC DEPARTMENT;
vtucode.in Page 40
DBMS Laboratory with mini Project 21CSL55
DESC DLOCATION;
DESC PROJECT;
DESC PROJECT;
DESC WORKS_ON;
Note: update entries of employee table to fill missing fields SUPERSSN and DNO
UPDATE EMPLOYEE SET SUPE
UPDATE EMPLOYEE
vtucode.in Page 42
DBMS Laboratory with mini Project 21CSL55
INSERT INTO PROJECT VALUES (106,'OPENSTACK','BANGALORE','4');
INSERT INTO PROJECT VALUES (107,'SMART CITY','BANGALORE','2');
vtucode.in Page 43
DBMS Laboratory with mini Project 21CSL55
SELECT * FROM DLOCATION ;
vtucode.in Page 44
DBMS Laboratory with mini Project 21CSL55
Queries:
1. Make a list of all project numbers for projects that involve an employee whose last name
UNION
(SELECT DISTINCT P1.PNO FROM PROJECT P1, WORKS_ON W, EMPLOYEE E1 WHERE
2.
percent raise.
SELECT E.FNAME, E.LNAME, 1.1*E.SALARY AS INCR_SAL FROM EMPLOYEE E,
WORKS_ON W, PROJECT P WHERE E.SSN=W.SSN AND W.PNO=P.PNO AND
3.
maximum salary, the minimum salary, and the average salary in this department
SELECT SUM (E.SALARY), MAX (E.SALARY), MIN (E.SALARY), AVG (E.SALARY)
FROM EMPLOYEE E, DEPARTMENT D WHERE E.DNO=D.DNO AND
vtucode.in Page 45
DBMS Laboratory with mini Project 21CSL55
4. Retrieve the name of each employee who works on all the projects Controlled by
department number 5 (use NOT EXISTS operator).
SELECT E.FNAME,E.LNAME FROM EMPLOYEE E WHERE NOT EXISTS
(SELECT PNO FROM PROJECT P WHERE DNO=5 AND PNO NOT IN
(SELECT PNO FROM WORKS_ON W 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 E.SALARY>600000
AND D.DNO IN (SELECT E1.DNO
FROM EMPLOYEE E1
GROUP BY E1.DNO
HAVING COUNT (*)>5)
GROUP BY D.DNO;
Program Outcomes:
The students are able to
Create, Update and query on the database.
Demonstrate the working of different concepts of DBMS
Implement, analyze and evaluate the project developed for an application.
vtucode.in Page 46
DBMS Laboratory with mini Project 21CSL55
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 aspect 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 user 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 a 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. Disadvantage in File Processing System?
Data redundancy & inconsistency.
Difficult in accessing data.
Data isolation.
Data integrity.
Concurrent access is not possible.
Security Problems.
7. Define the "integrity rules"
There are two Integrity rules.
Entity Integrity: States that key cannot have NULL
be either a NULL value or should
be Primary Key value of other relation.
vtucode.in Page 47
DBMS Laboratory with mini Project 21CSL55
8. 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 is 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.
9. What is Data Model?
A collection of conceptual tools for describing data, data relationships, data semantics and
constraints.
10. 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.
11. 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.
12. What is an Entity?
It is an 'object' in the real world with an independent existence.
13. What is an Entity type?
It is a collection (set) of entities that have same attributes.
14. What is an attribute?
It is a particular property, which describes the entity.
15. What is degree of a Relation?
It is the number of attribute of its relation schema.
16. What is Relationship?
It is an association among two or more entities.
17. What is DDL (Data Definition Language)?
A data base schema is specified by a set of definitions expressed by a special language
called DDL.
18. What is DML (Data Manipulation Language)?
This language that enable user to access or manipulate data as organized by appropriate
vtucode.in Page 48
DBMS Laboratory with mini Project 21CSL55
data model.
vtucode.in Page 49
DBMS Laboratory with mini Project 21CSL55
26. What are partial, alternate,, artificial, compound and natural key?
Partial Key:
It is a set of attributes that can uniquely identify weak entities and that are related to same
owner entity. It is sometime called as Discriminator.
Alternate Key:
All Candidate Keys excluding the Primary Key are known as Alternate Keys.
Artificial Key:
If no obvious key, either standalone or compound is available, then the last resort is to
simply create a key, by assigning a unique number to each record or occurrence. Then this is
known as developing an artificial key.
Compound Key:
If no single data element uniquely identifies occurrences within a construct, then combining
multiple elements to create a unique identifier for the construct is known as creating a
compound key.
Natural Key:
When one of the data elements stored within a construct is utilized as the primary key, then
it is called the natural key.
27. What is meant by query optimization?
The phase that identifies an efficient execution plan for evaluating a query that has the least
estimated cost is referred to as query optimization.
28. What do you mean by atomicity and aggregation?
Atomicity:
Either all actions are carried out or none are. Users should not have to worry about the effect
of incomplete transactions. DBMS ensures this by undoing the actions of incomplete
transactions.
Aggregation:
A concept which is used to model a relationship between a collection of entities and
relationships. It is used when we need to express a relationship among relationships.
29. What is a checkpoint and when does it occur?
A Checkpoint is like a snapshot of the DBMS state. By taking checkpoints, the DBMS can
reduce the amount of work to be done during restart in the event of subsequent crashes.
vtucode.in Page 50
DBMS Laboratory with mini Project 21CSL55
capabilities but is user-friendly and provides user-interface management.
31. Brief theory of Network, Hierarchical schemas and their properties
Network schema uses a graph data structure to organize records example for such a database
management system is CTCG while a hierarchical schema uses a tree data structure example
for such a system is IMS.
32. What is a query?
A query with respect to DBMS relates to user commands that are used to interact with a data
base. The query language can be classified into data definition language and data
manipulation language.
33. What do you mean by Correlated subquery?
Subqueries, or nested queries, are used to bring back a set of rows to be used by the parent
query. Depending on how the subquery is written, it can be executed once for the parent
query or it can be executed once for each row returned by the parent query. If the subquery
is executed for each row of the parent, this is called a correlated subquery.
A correlated subquery can be easily identified if it contains any references to the parent
subquery columns in its WHERE clause. Columns from the subquery cannot be referenced
anywhere else in the parent query. The following example demonstrates a non-correlated
subquery.
' IN (Select ODATE From ORDER Where
CUST.CNUM = ORDER.CNUM)
34. What are the primitive operations common to all record management systems?
Addition, deletion and modification
35. How do you communicate with an RDBMS?
You communicate with an RDBMS using Structured Query Language (SQL)
36. Define SQL and state the differences between SQL and other conventional
programming Languages
SQL is a nonprocedural language that is designed specifically for data access operations on
normalized relational database structures. The primary difference between SQL and other
conventional programming languages is that SQL statements specify what data operations
should be performed rather than how to perform them.
37. What is database Trigger?
A database trigger is a PL/SQL block that can defined to automatically execute for insert,
update, and delete statements against a table. The trigger can e defined to execute once for
the entire statement or once for every row that is inserted, updated, or deleted.
vtucode.in Page 51
DBMS Laboratory with mini Project 21CSL55
38. What are stored-procedures? And what are the advantages of using them.
Stored procedures are database objects that perform a user defined operation. A stored
procedure can have a set of compound SQL statements. A stored procedure executes the
SQL commands and return the result to the client. Stored procedures are used to reduce
network traffic.
39. Which is the subset of SQL commands used to manipulate Database structures,
including tables?
Data Definition Language (DDL)
40. What operator performs pattern matching?
LIKE operator
41. What operator tests column for the absence of data?
IS NULL operator
42. What are the wildcards used for pattern matching?
For single character substitution and % for multi-character substitutio
43. What are the difference between TRUNCATE and DELETE commands?
TRUNCATE DELETE
44. What is the use of the ADD OR DROP option in the ALTER TABLE command?
It is used to add/drop columns or add/drop constraints specified on the table
45. What is the use of DESC in SQL?
DESC has two purposes. It is used to describe a schema as well as to retrieve rows from table in
descending order.
The query SELECT * FROM EMP ORDER BY ENAME DESC will display the output sorted
on ENAME in descending order
46. What is the use of ON DELETE CASCADE?
Whenever rows in the master (referenced) table are deleted ,the respective rows of the child
(referencing) table with a matching foreign key column will get deleted as well. This is called a
cascade delete
vtucode.in Page 52
DBMS Laboratory with mini Project 21CSL55
Example Tables:
CREATE TABLE Customer
(
customer_id INT (6) PRIMARY KEY,
cname VARCHAR (100),
caddress VARCHAR (100)
);
vtucode.in Page 53
DBMS Laboratory with mini Project 21CSL55
50. What you mean by SQL UNIQUE Constraint?
The UNIQUE constraint ensures that all values in a column are different.
Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for uniqueness for a
column or set of columns.
A PRIMARY KEY constraint automatically has a UNIQUE constraint.
However, you can have many UNIQUE constraints per table, but only one PRIMARY KEY
constraint per table.
51. How to add and drop UNIQUE Constraint in table in mysql?
ALTER TABLE contacts ADD CONSTRAINT UNC_name_email UNIQUE(name,email)
ALTER TABLE contacts DROP INDEX UNC_name_email;
52. What is the Group by Clause?
The GROUP BY clause is a SQL command that is used to group rows that have the same
values.
The GROUP BY clause is used in the SELECT statement .Optionally it is used in conjunction
with aggregate functions to produce summary reports from the database.That's what it
does, summarizing data from the database.
The queries that contain the GROUP BY clause are called grouped queries and only return
single row for every grouped item.
Example:SELECT COUNT(CustomerID), Country FROM Customers
GROUP BY Country
53. What is use of having clause in mysql
The HAVING clause is used in the SELECT statement to specify filter conditions for a group of
rows or aggregates.
The HAVING clause is often used with the GROUP BY clause to filter groups based on a
specified condition. If the GROUP BY clause is omitted, the HAVING clause behaves like
the WHERE clause.
Notice that the HAVING clause applies a filter condition to each group of rows, while
the WHERE clause applies the filter condition to each individual row.
Example:SELECT COUNT(CustomerID), Country FROM Customers
GROUP BY Country HAVING COUNT(CustomerID) > 5;
54. What is distinct clause in SQL?
When querying data from a table, you may get duplicate rows. In order to remove these duplicate
rows, you use the DISTINCT clause in the SELECT statement.
Example:SELECT DISTINCT columns FROM table_name WHERE where_conditions;
vtucode.in Page 54
DBMS Laboratory with mini Project 21CSL55
55. What is a union?
Unions combine the results from multiple SELECT queries into a consolidated result set.
The only requirements for this to work is that the number of columns should be the same from
all the SELECT queries which needs to be combined
56. What is use of MySQL Aggregate Functions?
The data that you need is not always directly stored in the tables. However, you can get it by
performing the calculations of the stored data when you select it.
By definition, an aggregate function performs a calculation on a set of values and returns a
single value.
MySQL provides many aggregate functions that include AVG, COUNT, SUM, MIN, MAX, etc.
An aggregate function ignores NULL values when it performs calculation except for
the COUNT function.
Often, aggregate functions are accompanied by the GROUP BY clause of the SELECT
statement
Below are some of aggregate functions used in sql query
AVG function
The AVG function calculates the average value of a set of values. It ignores NULL values in the
calculation.
COUNT function
The COUNT function returns the number of the rows in a table. For example, you can use below
query .below query return number of employees in Employee table
SELECT COUNT (Empname) FROM Employee
SUM function
The SUM function returns the sum of a set of values. The SUM function ignores NULL values.
If no matching row found, the SUM function returns a NULL value.
The SUM function to get the sum of salary of employees in the Employee table
SELECT SUM(Salary) FROM Employee
MAX function
The MAX function returns the maximum value in a set of values.
Below query gets maximum salary of table Employee
SELECT MAX(Salary) FROM Employee
MIN function
The MIN function returns the minimum value in a set of values.
Below query returns minimum salary of table Employee
SELECT MIN(Salary) FROM Employee
vtucode.in Page 55
DBMS Laboratory with mini Project 21CSL55
Additional Queries
CREATE command
CREATE TABLE Employee
(
Empno int(4) primary key,
Empname varchar(50),
job varchar(40),
Hiredate date,
Salary decimal(10,2),
Deptno int(7),
Age int(10)
);
DESC command
DESC Employee;
INSERT command
Insert the values into the table as specified.
1) Insert into Employee -11-
2) Insert into Employee values(1001, -05- 45000, 10, 42);
3) Insert into Employee values(1002, ' -01- 000, 20, 28);
4) Insert into Employee values(100 -05- 15000, 40, 34);
5) Insert into Employee values(10 -10- 60000, 50, 45);
6) Insert into Employee values(1005, -7-
vtucode.in Page 56
DBMS Laboratory with mini Project 21CSL55
Queries:
Problems on select command:
2) Display the details of all employees getting salary less than 30,000.
8-03-
9) Display the details of employees whose names does not starts with
10) Display the employee details whose names have exactly 4 characters.
11)Copy all the records of their from employee table and insert the records into a temp table
with column names same as in Employee table
vtucode.in Page 57
DBMS Laboratory with mini Project 21CSL55
1. Update the salary by 10% hike to Manager working in department number 20 and 30
SOL: UPDATE EMP SET SAL = SAL * 1. 1 WHERE Deptno IN (20,30) AND JOB
=
2. Give 5% raise in salary to all the Salesman
SOL1:UPDATE EMPLOYEE SET Salary=Salary*1.15 WHERE JOB='Salesman';
OR
SOL2 :UPDATE EMPLOYEE SET Salary=Salary+(Salary * 15/100) WHERE
JOB='Salesman';
3. Change the department no of Sachin to 40
SOL: UPDATE EMP SET DEPTNO = 40 WHERE Empname
4. Update all employee name to uppercase
SOL: UPDATE EMPLOYEE SET Empname=upper(Empname);
ALTER command
vtucode.in Page 58
DBMS Laboratory with mini Project 21CSL55
4. How to add column Commission in Employee table?
ALTER TABLE Employee add Commission varchar(40);
5. How to drop column Commission in Employee table?
ALTER TABLE Employee DROP column Commission;
6. How to add primary key to Employee table?
ALTER TABLE Employee add primary key(Empno);
7. How to drop primary key to Employee table?
ALTER TABLE Employee DROP primary key;
8. How to rename employee table?
RENAME TABLE Employee to Employee_Details
9. How to delete contents of Employee table?
DELETE FROM Employee;
OR
TRUNCATE Employee;
10. How to drop Employee table?
DROP TABLE Employee;
11. How to drop database name COLLEGE?
DROP DATABASE COLLEGE
vtucode.in Page 59