Dbms Lab 5th Sem Manual - Bmsece
Dbms Lab 5th Sem Manual - Bmsece
Dbms Lab 5th Sem Manual - Bmsece
Prepared by:
Poornima
Dept. Of CSE, BMSECE,
Basavangudi, Bangalore
25-Aug-19 Page 1 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Table of Contents
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING ......................................................................... 1
Important Notes: .......................................................................................................................................... 3
VTU Syllabus – DBMS Lab Experiment ...................................................................................................... 4
Tool Pictorial Description .......................................................................................................................... 7
Data type conversion .................................................................................................................................... 8
PART-A : SQL Programming....................................................................................................................... 9
PROGRAM – 1............................................................................................................................................ 9
Describe Table. .................................................................................................................................... 12
Select Statement .................................................................................................................................. 13
Query & Output ................................................................................................................................... 14
PROGRAM – 2.......................................................................................................................................... 16
Describe Table. .................................................................................................................................... 18
Select Statement .................................................................................................................................. 19
Query & Output ................................................................................................................................... 19
PROGRAM – 3.......................................................................................................................................... 22
Describe Table. .................................................................................................................................... 25
Select Statement .................................................................................................................................. 25
Query & Output ................................................................................................................................... 26
PROGRAM – 4.......................................................................................................................................... 28
Describe Table. .................................................................................................................................... 32
Select Statement .................................................................................................................................. 33
Query & Output ................................................................................................................................... 34
PROGRAM – 5.......................................................................................................................................... 41
Describe Table. .................................................................................................................................... 45
Select Statement .................................................................................................................................. 46
Query & Output ................................................................................................................................... 47
VIVA Questions ........................................................................................................................................... 50
25-Aug-19 Page 2 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Important Notes:
Before you begin, make sure the necessary software have been installed on your Lab machine.
As per VTU, colleges have an option of choosing any DBMS tools like Oracle, MS-SQL, MySQL etc.
Hence we have used Microsoft SQL Server 2008 R2 Express Edition on Windows XP for the
same.
25-Aug-19 Page 3 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 4 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 5 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
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.
Part B: Mini project
For any problem selected, write the ER Diagram, apply ER-mapping rules,
normalize the relations, and follow the application development process.
Make sure that the application should have five or more tables, at least one
trigger and one stored procedure, using suitable frontend tool.
Indicative areas include; health care, education, industry, transport, supply chain,
etc.
Course outcomes: The students should be able to:
Use Structured Query Language (SQL) for database Creation and manipulation.
Demonstrate the working of different concepts of DBMS
Implement and test the project developed for an application.
Conduction of Practical Examination:
1. All laboratory experiments from part A are to be included for practical
examination.
2. Mini project has to be evaluated for 40 Marks.
3. Report should be prepared in a standard format prescribed for project work.
4. Students are allowed to pick one experiment from the lot.
5. Strictly follow the instructions as printed on the cover page of answer script.
6. Marks distribution:
a) Part A: Procedure + Conduction + Viva: 09 + 42 +09 =60 Marks
7. Part B: Demonstration + Report + Viva voce = 20+14+06 = 40 Marks
8. Change of experiment is allowed only once and marks allotted to the procedure
part to be made zero.
25-Aug-19 Page 6 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Below pictorial notation and tooltip specifics the overview of SQL Server Management Studio.
25-Aug-19 Page 7 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
ORACLE SQL
(Data type) To → (Data type)
CHAR → CHAR
VARCHAR2 → VARCHAR
NCHAR → NCHAR
NCHAR → NVARCHAR
NUMBER(3) → BIT
NUMBER(3) → INTYINT
NUMBER(5) → SMALLINT
NUMBER(10) → INTEGER
FLOAT(49) → FLOAT
FLOAT(23) → REAL
NUMBER(P[,S]) → NUMERIC
NUMBER(P[,S]) → DECIMAL
NUMBER(10,4) → SMALL MONEY
NUMBER(19,4) → MONEY
DATE → SMALL DATETIME
DATE → DATETIME
LONG → TEXT
LONG → NTEXT
RAW → TIMESTAMP
RAW → BINARY
RAW → VARBINARY
LONGRAW → IMAGE
Note:
While creating PK FK relationship, you have to include data type of respective column before
the references keyword.
MINUS Clause in Oracle has equivalent as EXPECT clause in SQL
PL/SQL is called as Store Procedure in MS-SQL
All the queries have been tried, tested and executed in MS-SQL 2008.
DESC SP_HELP – To Describe a table to see its schema
25-Aug-19 Page 8 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
PROGRAM – 1
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)
Write SQL queries to
1. Retrieve details of all books in the library – id, title, name of publisher, authors,
number of copies in each branch, etc.
2. Get the particulars of borrowers who have borrowed more than 3 books, but from Jan
2017 to Jun 2017.
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.
Create a view of all books and its number of copies that are currently available in the Library.
25-Aug-19 Page 9 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 10 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 11 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Describe Table.
For Demo purpose only one table has been described. Perform describe for all the tables.
25-Aug-19 Page 12 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Select Statement
25-Aug-19 Page 13 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 14 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 15 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
PROGRAM – 2
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) Write SQL queries to
1. Count the customers with grades above Bangalore’s average.
2. Find the name and numbers of all salesman who had more than one customer.
3. List all the salesman and indicate those who 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 also be deleted.
25-Aug-19 Page 16 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Schema Diagram:
25-Aug-19 Page 17 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Describe Table.
25-Aug-19 Page 18 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Select Statement
25-Aug-19 Page 19 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 20 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 21 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
PROGRAM – 3
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 a 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.
25-Aug-19 Page 22 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 23 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 24 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Describe Table.
Select Statement
25-Aug-19 Page 25 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 26 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 27 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
PROGRAM – 4
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) Write SQL queries
to
1. List all the student 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 ‘1BI17CS101’ 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.
25-Aug-19 Page 28 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 29 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 30 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 31 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Describe Table.
25-Aug-19 Page 32 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Select Statement
25-Aug-19 Page 33 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 34 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 35 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 36 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Note: You need to create a user defined function called GREATEST. Oracle has built in function
called GREATEST. But in MS-SQL we have Max. In order to support multiple parameters Max
function does not support. Hence we have created a very simple custom function called
greatest which returns largest of two given integer input.
25-Aug-19 Page 37 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 38 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 39 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 40 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
PROGRAM – 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 ‘Scott’, either as a worker or as a manager 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 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.
Solution:
25-Aug-19 Page 41 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 42 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 43 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 44 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Describe Table.
25-Aug-19 Page 45 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Select Statement
25-Aug-19 Page 46 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 47 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 48 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 49 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
VIVA Questions
1. What is database?
A database is a collection of information that is organized. So that it can easily be accessed, managed,
and updated.
2. What is DBMS?
DBMS stands for Database Management System. It is a collection of programs that enables user to
create and maintain a database.
3. What is a Database system?
The database and DBMS software together is called as Database system.
4. What are the advantages of DBMS?
I. Redundancy is controlled.
II. Providing multiple user interfaces.
III. Providing backup and recovery
IV. Unauthorized access is restricted.
V. Enforcing integrity constraints.
5. What is normalization?
It is a process of analysing the given relation schemas based on their Functional Dependencies (FDs)
and primary key to achieve the properties
(1).Minimizing redundancy, (2). Minimizing insertion, deletion and update anomalies.
6. What is Data Model?
A collection of conceptual tools for describing data, data relationships data semantics and constraints.
7. 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.
8. What is Object Oriented model?
This model is based on collection of objects. An object contains values stored in instance variables with
in 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.
9. What is an Entity?
An entity is a thing or object of importance about which data must be captured.
10. What is DDL (Data Definition Language)?
A data base schema is specifies by a set of definitions expressed by a special language called DDL.
25-Aug-19 Page 50 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 51 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 53 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
A homogenous database is one that uses the same DBMS at each node. A heterogeneous database is
one that may have a different DBMS at each node.
25-Aug-19 Page 54 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
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.
25-Aug-19 Page 55 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 56 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
70. What is Enterprise Resource Planning (ERP), and what kind of a database is used in an ERP
application?
Enterprise Resource Planning (ERP) is an information system used in manufacturing companies and
includes sales, inventory, production planning, purchasing and other business functions. An ERP system
typically uses a multiuser database.
25-Aug-19 Page 57 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
unique secondary index is unique for each row and used to find table rows. A nonunique secondary
index is not unique and used to find table rows.
78. Explain minimum and maximum cardinality?
Minimum cardinality is the minimum number of instances of an entity that can be associated with each
instance of another entity. Maximum cardinality is the maximum number of instances of an entity that
can be associated with each instance of another entity.
79. What is deadlock? How can it be avoided? How can it be resolved once it occurs?
Deadlock occurs when two transactions are each waiting on a resource that the other transaction
holds. Deadlock can be prevented by requiring transactions to acquire all locks at the same time; once it
occurs, the only way to cure it is to abort one of the transactions and back out of partially completed
work.
80. Explain what we mean by an ACID transaction.
An ACID transaction is one that is atomic, consistent, isolated, and durable. Durable means that
database changes are permanent. Consistency can mean either statement level or transaction level
consistency. With transaction level consistency, a transaction may not see its own changes.Atomic
means it is performed as a unit.
81. Under what conditions should indexes be used?
Indexes can be created to enforce uniqueness, to facilitate sorting, and to enable fast retrieval by
column values. A good candidate for an index is a column that is frequently used with equal conditions
in WHERE clauses.
82. What is difference between SQL and SQL SERVER?
SQL is a language that provides an interface to RDBMS, developed by IBM. SQL SERVER is a RDBMS just
like Oracle, DB2.
83. What is Specialization?
It is the process of defining a set of subclasses of an entity type where each subclass contain all the
attributes and relationships of the parent entity and may have additional attributes and relationships
which are specific to itself.
84. What is generalization?
It is the process of finding common attributes and relations of a number of entities and defining a
common super class for them.
85. What is meant by Proactive, Retroactive and Simultaneous Update?
Proactive Update: The updates that are applied to database before it becomes effective in real world.
Retroactive Update: The updates that are applied to database after it becomes effective in real world.
Simultaneous Update: The updates that are applied to database at the same time when it becomes
effective in real world.
86. What is RAID Technology?
25-Aug-19 Page 58 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
Redundant array of inexpensive (or independent) disks. The main goal of raid technology is to even out
the widely different rates of performance improvement of disks against those in memory and
microprocessor. Raid technology employs the technique of data striping to achieve higher transfer
rates.
87. What are serial, non serial schedule?
A schedule S is serial if, for every transaction T participating in the schedule, all the operations of T is
executed consecutively in the schedule, otherwise, the schedule is called non-serial schedule.
88. What are conflict serializable schedules?
A schedule S of n transactions is serializable if it is equivalent to some serial schedule of the same n
transactions.
89. What is view serializable?
A schedule is said to be view serializable if it is view equivalent with some serial schedule.
90. What is a foreign key?
A key of a relation schema is called as a foreign key if it is the primary key of
some other relation to which it is related to.
91. What are the disadvantages of using a dbms?
1) High initial investments in h/w, s/w, and training.
2) Generality that a DBMS provides for defining and processing data.
3) Overhead for providing security, concurrency control, recovery, and integrity functions.
92. What is Lossless join property?
It guarantees that the spurious tuple generation does not occur with respect to relation schemas after
decomposition.
93. What is a Phantom Deadlock?
In distributed deadlock detection, the delay in propagating local information might cause the deadlock
detection algorithms to identify deadlocks that do not really exist. Such situations are called phantom
deadlocks and they lead to unnecessary aborts.
94. 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.
95. What is schema?
The description of a data base is called the database schema , which is specified during database design
and is not expected to change frequently . A displayed schema is called schema diagram .We call each
object in the schema as schema construct.
96. What is the difference between ORDERBY and GROUPBY?
A. ORDERBY performs sorting while GROUPBY AGGREGATES Data
B. GROUPBY sorts data while ORDERBY puts data in order
C. Both perform sorting.
25-Aug-19 Page 59 of 60
DBMS Lab Manual, BMSECE Subject Code: 17CSL58
25-Aug-19 Page 60 of 60