Final Lab Manual - BDMS-2024-25
Final Lab Manual - BDMS-2024-25
EXPERIMENT NO – 1
Aim:- Introduction to DBMS
Theory:
DBMS (Database Management System)
A DBMS is software that allows creation, definition and manipulation of database,
allowing users to store, process and analyze data easily. DBMS provides us with an interface
or a tool, to perform various operations like creating database, storing data in it, updating
data, creating tables in the database and a lot more.
DBMS also provides protection and security to the databases. It also maintains data
consistency in case of multiple users.
Here are some examples of popular DBMS used these days:
MySql
Oracle
SQL Server
IBM DB2
PostgreSQL
Amazon SimpleDB (cloud based) etc.
MANOHARBHAI PATEL INSTITUTE OF ENGINEERING AND
TECHNOLOGY SHAHAPUR, BHANDARA
DEPARTMENT OF COMPUTER ENGINEERING
Semester : FIFTH Subject Code: BTCME501P DBMS Lab Manual
Advantages of DBMS
Segregation of application program.
Minimal data duplicity or data redundancy.
Easy retrieval of data using the Query Language.
Reduced development time and maintenance need.
MANOHARBHAI PATEL INSTITUTE OF ENGINEERING AND
TECHNOLOGY SHAHAPUR, BHANDARA
DEPARTMENT OF COMPUTER ENGINEERING
Semester : FIFTH Subject Code: BTCME501P DBMS Lab Manual
With Cloud Datacenters, we now have Database Management Systems capable of
storing almost infinite data.
Seamless integration into the application programming languages which makes it very
easier to add a database to almost any application or website.
Disadvantages of DBMS
It's Complexity
Except MySQL, which is open source, licensed DBMSs are generally costly.
They are large in size.
RDBMS (Relational Database management System)
A Relational Database management System (RDBMS) is a database management
system based on the relational model introduced by E.F Codd. In relational model, data is
stored in relations (tables) and is represented in form of tuples (rows).
RDBMS is used to manage Relational database. Relational database is a collection of
organized set of tables related to each other, and from which data can be accessed easily.
Relational Database is the most commonly used database these days.
In relational model in which data is stored in multiple tables where tables are related to each
other using primary keys and foreign keys and indexes. RDBMS uses database normalization
techniques to avoid redundancy in tables. It helps to fetch data faster using SQL query. It is
widely used by enterprises and software developers to store large amount of complex data
Examples:
SQL server,
Oracle
MySQL
MariaDB
SQLite
Table
In Relational database model, a table is a collection of data elements organized in terms of
rows and columns. A table is also considered as a convenient representation of relations. But
a table can have duplicate row of data while a true relation cannot have duplicate data. Table
is the simplest form of data storage. Below is an example of an Employee table.
MANOHARBHAI PATEL INSTITUTE OF ENGINEERING AND
TECHNOLOGY SHAHAPUR, BHANDARA
DEPARTMENT OF COMPUTER ENGINEERING
Semester : FIFTH Subject Code: BTCME501P DBMS Lab Manual
1 Adam 34 13000
2 Alex 28 15000
3 Stuart 20 18000
4 Ross 42 19020
Tuple
A single entry in a table is called a Tuple or Record or Row. A tuple in a table represents a
set of related data. For example, the above Employee table has 4 tuples/records/rows.
Following is an example of single record or tuple.
1 Adam 34 13000
Attribute
A table consists of several records (row), each record can be broken down into several
smaller parts of data known as Attributes. The above Employee table consists of four
attributes, ID, Name, Age and Salary.
Attribute Domain
When an attribute is defined in a relation (table), it is defined to hold only a certain type of
values, which is known as Attribute Domain. Hence, the attribute Name will hold the name
of employee for every tuple. If we save employee's address there, it will be violation of the
Relational database model.
Name
Adam
Alex
Conclusion: Thus we, have studied DBMS, RDBMS with its advantages and disadvantages
successfully.
DDL: A data definition language or data description language (DDL) is syntax similar to a
computer programming language for defining data structures, especially database schemas.-
Commands in DDL are:
a. CREATE
b. DROP
c. TRUNCATE
d. RENAME
e. ALTER.
a) CREATE Statement:
Create table <tablename> (<column_name1 > <data_ type_1>, <column_name2> <data_
type _2>,……,<column_nameN > <data_ type_N>, ……<.constraint1>, <constraint2>,
…….);
b) DROP:
DROP TABLE < table_name>;
c) TRUNCATE: The SQL TRUNCATE TABLE command is used to delete complete data
from an existing table.
TRUNCATE TABLE <table_name>;
e) ALTER:
Note: Solve the following queries and show respective results on blank side of record
book.
DDL QUERIES:
Q1. Write a query to create a table employee with empno, ename, designation, and salary.
Q2. Write a query for create a from an existing table with all the fields.
Q3. Write a Query to Alter the column EMPNO NUMBER(4) TO EMPNO NUMBER(6).
Conclusion: Thus we, have implemented Data Definition Language commands (Create,
Alter, Drop, Truncate, and Rename) successfully.
1. What is SQL?
2. What is difference between Truncate and Drop Command?
3. What is difference between Truncate and Delete Command?
4. What is mean by integrity constraints?
5. What are different integrity constraints?
MANOHARBHAI PATEL INSTITUTE OF ENGINEERING AND
TECHNOLOGY SHAHAPUR, BHANDARA
DEPARTMENT OF COMPUTER ENGINEERING
Semester : FIFTH Subject Code: BTCME501P DBMS Lab Manual
Experiment No.3
a.INSERT
b.UPDATE
c.DELETE
d.SELECT
DML COMMANDS:
SYNTAX:
a) INSERT Statement: The INSERT statement is a SQL query. It is used to insert data into
the row of a table.
Or
INSERT INTO <TABLE_NAME> (col1, col2, col3,.... col N) VALUES (value1, value2, val
ue3, .... valueN);
b) UPDATE Statement: This command is used to update or modify the value of a column in
the table.
d.SELECT statement : SELECT statement is used to query or retrieve data from a table in
the database. The returns data is stored in a table, and the result table is known as result-set.
Note: Solve the following queries and show respective results on blank side of record
book.
DML QUERIES:
1. What is DML?
2. What is mean by extension?
3. What is difference between DROP and DELETE Command?
4. What is indexing?
5. What are basic data types in SQL?
MANOHARBHAI PATEL INSTITUTE OF ENGINEERING AND
TECHNOLOGY SHAHAPUR, BHANDARA
DEPARTMENT OF COMPUTER ENGINEERING
Semester : FIFTH Subject Code: BTCME501P DBMS Lab Manual
Experiment No.4
Arithmetic operators
Comparison operators
Logical operators
Note: Solve the following queries and show respective results on blank side of record
book
MANOHARBHAI PATEL INSTITUTE OF ENGINEERING AND
TECHNOLOGY SHAHAPUR, BHANDARA
DEPARTMENT OF COMPUTER ENGINEERING
Semester : FIFTH Subject Code: BTCME501P DBMS Lab Manual
Conclusion: Thus we have implemented SQL queries using different types of operators
successfully.
Experiment No.5
Aggregate functions are functions that take a collection (a set or multiset) of values as input
and return a single value. SQL offers five built-in aggregate functions. It is also used to
summarize the data. This type of scenario is where you would use a group functions.
To use a group function in a SQL query, list the function name followed by numeric
column name within parentheses. AVG averages the column, COUNT counts the number of
items, MAX returns maximum number of the column, and MIN returns minimum number of
the column .The following is query to retrieve total price, average price, maximum price, and
minimum price from the table “product” assuming the product table has the following values.
MANOHARBHAI PATEL INSTITUTE OF ENGINEERING AND
TECHNOLOGY SHAHAPUR, BHANDARA
DEPARTMENT OF COMPUTER ENGINEERING
Semester : FIFTH Subject Code: BTCME501P DBMS Lab Manual
Note: Solve the following queries and show respective results on blank side of record
book
SUM(PRICE) 870 This statement will returns the total amount for the column price which is
870.
Avg(price) 217.50 This statement will returns the average amount for the column price which
is 870/4 or 217.50.
Max(price) 300 This statement will returns the maximum amount for the column price which
is 300
Min(price) 120 This statement will returns the maximum amount for the column price which
is 120
Conclusion: Thus we have implemented SQL queries for Aggregate functions successfully.
Experiment No.6
DBMS supports relational set operators. Set operations correspond to the mathematical set-
theory operations ∪, ∩, and −.The major relational set operators are union, intersection and
set difference. All of these can be implemented in DBMS using different queries.
Table 1: Art_Students
Table 2: Dance_Students
1. Union
Union combines two different results obtained by a query into a single result in the
form of a table. However, the results should be similar if union is to be applied on them.
Union removes all duplicates, if any from the data and only displays distinct values. If
duplicate values are required in the resultant data, then UNION ALL is used.
UNION
This will display the names of all the students in the table Art_Students and Dance_Students
i.e John, Mary, Damon and Matt.
2. Intersection
The intersection operator gives the common data values between the two data sets that
are intersected. The two data sets that are intersected should be similar for the intersection
operator to work. Intersection also removes all duplicates before displaying the result.
An example of intersection is:
INTERSECT
This will display the names of the students in the table Art_Students and in the table
Dance_Students i.e all the students that have taken both art and dance classes .Those are
Mary and Damon in this example.
MINUS/EXCEPT
This will display the names of all the students in table Art_Students but not in table
Dance_Students i.e the students who are taking art classes but not dance classes.
That is John in this example.
MANOHARBHAI PATEL INSTITUTE OF ENGINEERING AND
TECHNOLOGY SHAHAPUR, BHANDARA
DEPARTMENT OF COMPUTER ENGINEERING
Semester : FIFTH Subject Code: BTCME501P DBMS Lab Manual
Conclusion: Thus we have implemented SQL queries for set operations successfully
Experiment No.7
Aim: - Implement SQL queries for sub queries, nested queries and to
create views.
Theory:
Nested Queries: Nesting of queries one within another is known as a nested queries. Sub
queries. The query within another is known as a sub query. A statement containing sub query
is called parent statement. The rows returned by sub query are used by the parent statement.
Types
1. Sub queries that return several values Sub queries can also return more than one value.
Such results should be made use along with the operators in and any.
2. Multiple queries here more than one sub query is used. These multiple sub queries are
combined by means of “and” & “or‟ keywords.
3. Correlated sub query: A sub query is evaluated once for the entire parent statement
whereas a correlated Sub query is evaluated once per row processed by the parent statement.
The purpose of a join concept is to combine data spread across tables. A join is actually
performed by the “where‟ clause which combines specified rows of tables.Syntax; select
columns from table1, table2 where logical expression.
Types of Joins
1. Simple Join
b) Non Equi-join: It specifies the relationship between Table Aliases [Table aliases are used
to make multiple table queries shorted and more readable. We give an alias name to the table
in the “from‟ clause and use it instead of the name throughout the query].
MANOHARBHAI PATEL INSTITUTE OF ENGINEERING AND
TECHNOLOGY SHAHAPUR, BHANDARA
DEPARTMENT OF COMPUTER ENGINEERING
Semester : FIFTH Subject Code: BTCME501P DBMS Lab Manual
Self join: Joining of a table to itself is known as self-join. It joins one row in a table to
another. It can compare each row of the table to itself and also with other rows of the same
table.
Outer Join: It extends the result of a simple join. An outer join returns all the rows returned
by simple join as well as those rows from one table that do not match any row from the table.
The symbol (+) represents outer joins.
Inner join: Inner join returns the matching rows from the tables that are being joined.
Q1. Display all employee names and salary whose salary is greater than minimum salary of
the company and job title starts with “A‟.
SQL>select ename,sal from emp where sal>(select min(sal) from emp where job like 'A%');
Output:
View:
A view is nothing more than a SQL statement that is stored in the database with an
associated name. A view is actually a composition of a table in the form of a predefined SQL
query.
A view can contain all rows of a table or select rows from a table. A view can be created
from one or many tables which depends on the written SQL query to create a view. Views,
which are a type of virtual tables allow users to do the following −
Structure data in a way that users or classes of users find natural or intuitive.
Restrict access to the data in such a way that a user can see and (sometimes) modify
exactly what they need and no more.
MANOHARBHAI PATEL INSTITUTE OF ENGINEERING AND
TECHNOLOGY SHAHAPUR, BHANDARA
DEPARTMENT OF COMPUTER ENGINEERING
Semester : FIFTH Subject Code: BTCME501P DBMS Lab Manual
Summarize data from various tables which can be used to generate reports.
Queries:
Q1. Write a SQL query to create a view of customer table created in PRACTICAL no 1.
Output:
Conclusion: Thus we have implemented SQL queries for sub queries, nested queries and to
create views successfully.
Experiment No.8
Transaction Control Language (TCL) commands are used to manage transactions in database.
These are used to manage the changes made by DML statements. It also allows statements to
be grouped together into logical transactions. Commit command Commit command is used to
permanently save any transaction into database.
COMMIT;
Rollback command
This command restores the database to last commited state. It is also use with savepoint
command to jump to a savepoint in a transaction.
rollback to savepoint-name;
Savepoint command
Savepoint command is used to temporarily save a transaction so that you can rollback to that
point whenever necessary.
Savepoint <savepoint-name>;
QUERY:
Conclusion: Thus we have implemented SQL queries to understand the concepts for ROLL
BACK, COMMIT & CHECK POINTS successfully.
Experiment No.9
A SQL join clause combines columns from one or more tables in a relational
database. It creates a set that can be saved as a table or used as it is. A JOIN is a means for
combining columns from one (self-table) or more tables by using values common to each.
ANSI-standard SQL specifies five types of JOIN: INNER, LEFT OUTER, RIGHT OUTER,
FULL OUTER and CROSS. As a special case, a table (base table, view, or joined table) can
JOIN to itself in a self-join.
A programmer declares a JOIN statement to identify rows for joining. If the evaluated
predicate is true, the combined row is then produced in the expected format, a row set or a
temporary table.
Q1. Display the employee details, departments that the departments are same in both the emp
and dept.
Output:
Conclusion: Thus we have implemented SQL queries for different JOINS successfully.
Experiment No.10
The PL/SQL programming language was developed by Oracle Corporation in the late 1980s
as procedural extension language for SQL and the Oracle relational database. PL/SQL has the
following features −
Query:
DECLARE
a number (2) := 21;
b number (2) := 10;
BEGIN
IF (a = b) then
dbms_output.put_line('Line 1 - a is equal to b');
ELSE
dbms_output.put_line('Line 1 - a is not equal to b');
END IF;
IF (a < b) then
dbms_output.put_line('Line 2 - a is less than b');
MANOHARBHAI PATEL INSTITUTE OF ENGINEERING AND
TECHNOLOGY SHAHAPUR, BHANDARA
DEPARTMENT OF COMPUTER ENGINEERING
Semester : FIFTH Subject Code: BTCME501P DBMS Lab Manual
ELSE
dbms_output.put_line('Line 2 - a is not less than b');
END IF;
IF ( a> b ) THEN
dbms_output.put_line('Line 3 - a is greater than b');
ELSE
END IF;
END;
Output:
Line 1 - a is not equal to b
Line 2 - a is not less than b
Line 3 - a is greater than b
*******************************************