DBMS Lab File PDF
DBMS Lab File PDF
Objective:
To get to know about different RDBMS software
Problem Statement:
Compare 5 different RDBMS software and explain in detail
Comparison:
What are RDBMS software?
The relational model is the basis for a relational database management system
(RDBMS). Essentially, an RDBMS moves data into a database, stores the data, and
retrieves it so that it can be manipulated by applications. An RDBMS distinguishes
between the following types of operations:
Oracle Database: O
racle Database is an RDBMS that implements
object-oriented features such as user-defined types, inheritance and
polymorphism. Oracle database has extended the relational model to an
object-relational model, making it possible to store complex business models
1
in a relational database. One characteristic of an RDBMS is the independence
of physical data storage from logical data structures.
2
ii. PL/SQL and Java: P
L/SQL is a procedural extension to Oracle
SQL. PL/SQL is integrated with Oracle Database, enabling you to
use all of the Oracle Database SQL statements, functions, and
data types. You can use PL/SQL to control the flow of a SQL
program, use variables, and write error-handling procedures. A
primary benefit of PL/SQL is the ability to store application logic
in the database itself.
c. Transaction Management: O
racle Database is designed as a
multiuser database. The database must ensure that multiple users can
work concurrently without corrupting one another's data.
i. Transactions: A
n RDBMS must be able to group SQL
statements so that they are either all committed, which means
they are applied to the database, or all rolled back, which means
they are undone. A transaction is a logical, atomic unit of work
that contains one or more SQL statements.
ii. Data Concurrency: A requirement of a multiuser RDBMS is the
control of concurrency, which is the simultaneous access of the
same data by multiple users. Without concurrency controls,
users could change data improperly, compromising data
integrity. For example, one user could update a row while a
different user simultaneously updates it.
iii. Data Consistency: In Oracle Database, each user must see a
consistent view of the data, including visible changes made by a
user's own transactions and committed transactions of other
users. For example, the database must not permit a dirty read,
which occurs when one transaction sees uncommitted changes
made by another concurrent transaction.
d. Oracle database Architecture: A database server is the key to
information management. In general, a server reliably manages a large
amount of data in a multiuser environment so that users can
concurrently access the same data. A database server also prevents
3
unauthorized access and provides efficient solutions for failure
recovery.
i. Database and Instance: A
n Oracle database server consists of
a database and at least one database instance (commonly
referred to as simply an instance). Because an instance and a
database are so closely connected, the term Oracle database is
sometimes used to refer to both instance and database. In the
strictest sense the terms have the following meanings:
● Database
● A database is a set of files, located on disk, that store data.
These files can exist independently of a database instance.
● Database instance
● An instance is a set of memory structures that manage
database files. The instance consists of a shared memory
area, called the system global area (SGA), and a set of
background processes. An instance can exist independently
of database files.
ii. Database Storage Structures: An essential task of a relational
database is data storage. This section briefly describes the
physical and logical storage structures used by Oracle Database.
4
structure of the database, including the database name
and the names and locations of the database files.
● Online redo log files: Every Oracle Database has an online
redo log, which is a set of two or more online redo log files.
An online redo log is made up of redo entries (also called
redo records), which record all changes made to data.
5
Oracle Database Processes:
A process is a mechanism in an operating system that can run a
series of steps. Some operating systems use the terms j ob, t ask,
or t hread. For the purpose of this discussion, a thread is
equivalent to a process. An Oracle database instance has the
following types of processes:
6
information for one database instance. Examples of SGA
components include cached data blocks and shared SQL
areas.
● Program Global Areas (PGA): A PGA is a memory region that
contain data and control information for a server or
background process. Access to the PGA is exclusive to the
process. Each server process and background process has
its own PGA.
e. History: Initially, IBM had developed DB2 product for their specific
platform. Since year 1990, it decided to develop a Universal Database
(UDB) DB2 Server, which can run on any authoritative operating
systems such as Linux, UNIX, and Windows.
f. Versions: For IBM DB2, the UDB current version is 10.5 with the
features of BLU Acceleration and its code name as 'Kepler'.
g. Command Line Processor: The CLP can be started in one of the three
modes:
● Command mode: In this mode, each command and SQL
statement must be prefixed by “db2”. For example, query “db2
● Interactive input mode: you can launch this mode by using the
7
● Batch mode: Here, you need to create a script file, which
contains all SQL queries of requirements and save the file with
“.db2” extension. You can call this in command line using
path//T0000011/C000000.TMP/SQL00002.MEMBER0001.T
DA]
DB2TSCHG.HIS, DB2TSCHG.HIS]
8
● Logging-related files [SQLOGCTL.GLFH.1,
SQLOGCTL.GLFH.2]
SQLOGMIR.LFH].
database environment.
9
Transact-SQL (T-SQL), an implementation of SQL from Microsoft that adds a
set of proprietary programming extensions to the standard language.
i. It is a software, developed by Microsoft, which is implemented from
j. It is also an ORDBMS.
k. It is platform dependent.
m. It supports SQL (SEQUEL) language which is an IBM product,
a. To create databases.
b. To maintain databases.
(SSRS).
Services (SSIS).
SQL Server works in client-server architecture, hence it supports two
types of components − (a) W
orkstation and (b) Server.
10
● Workstation components are installed in every device/SQL
Server operator’s machine. These are just interfaces to interact
SQLEM etc.
SSAS, SSRS, SQL browser, SQL Server full text search etc.
Named.
Advantages of Instances:
b. To reduce cost.
11
c. To maintain production, development, and test environments
separately.
Organizations of all sizes use MongoDB to quickly and easily develop, scale
and operate applications. Instead of storing data in rows and columns as one
would with a relational database, MongoDB stores a binary form of JSON
documents (BSON).
12
Relational databases impose flat, rigid schemas across many tables. By
contrast, MongoDB is an agile database that allows schemas to vary across
documents and to change quickly as applications evolve, while still providing
the functionality developers expect from relational databases, such as
secondary indexes, a full query language and strong consistency.
Advantages of MongoDB:
13
● Tools to translate SQL to MongoDB queries are available, but they add
an extra step to using the engine.
● Setup can be a lengthy process.
● Default settings are not secure.
MYSQL Overview: M
ySQL is an Oracle-backed open source relational database
management system (RDBMS) based on Structured Query Language (SQL). MySQL
runs on virtually all platforms, including Linux, UNIX and Windows. Although it can
be used in a wide range of applications, MySQL is most often associated with web
applications and online publishing.
Originally conceived by the Swedish company MySQL AB, MySQL was acquired by
Sun Microsystems in 2008 and then by Oracle when it bought Sun in 2010.
Developers can use MySQL under the GNU General Public License (GPL), but
enterprises must obtain a commercial license from Oracle.
MySQL enables data to be stored and accessed across multiple storage engines,
including InnoDB, CSV, and NDB. MySQL is also capable of replicating data and
partitioning tables for better performance and durability. MySQL users aren't
14
required to learn new commands; they can access their data using standard SQL
commands.
MySQL is written in C and C++ and accessible and available across over 20
platforms, including Mac, Windows, Linux and Unix. The RDBMS supports large
databases with millions records and supports many data types including signed or
unsigned integers 1, 2, 3, 4, and 8 bytes long; FLOAT; DOUBLE; CHAR; VARCHAR;
BINARY; VARBINARY; TEXT; BLOB; DATE; TIME; DATETIME; TIMESTAMP; YEAR; SET;
ENUM; and OpenGIS spatial types. Fixed- and variable-length string types are also
supported.
For security, MySQL uses an access privilege and encrypted password system that
enables host-based verification. MySQL clients can connect to MySQL Server using
several protocols, including TCP/IP sockets on any platform. MySQL also supports a
number of client and utility programs, command-line programs and administration
tools such as MySQL Workbench.
Advantages of MySQL:
● Easy to Use
15
● Support available when needed
● Open Source
● Incredible Inexpensive
● Industry Standard
Disadvantages of MySQL:
● Stability issues
● Poor performance
● Development isn’t community driven
● Heavily dependant on addons
16
EXPERIMENT 2
Objective:
To learn the features of SQL
What is SQL?
SQL (Structured Query Language) is a standardized programming language that's
used to manage relational databases and perform various operations on the data
in them. Initially created in the 1970s, SQL is regularly used not only by database
administrators, but also by developers writing data integration scripts and data
analysts looking to set up and run analytical queries.
The uses of SQL include modifying database table and index structures; adding,
updating and deleting rows of data; and retrieving subsets of information from
within a database for transaction processing and analytics applications. Queries
and other SQL operations take the form of commands written as statements --
commonly used SQL statements include select, add, insert, update, delete, create,
alter and truncate.
Some characteristics of SQL:
● SQL is easy to learn.
● SQL is used to access data from relational database management systems.
● SQL can execute queries against the database.
● SQL is used to describe the data.
● SQL is used to define the data in the database and manipulate it when
needed.
● SQL is used to create and drop the database and table.
● SQL is used to create a view, stored procedure, function in a database.
● SQL allows users to set permissions on tables, procedures, and views.
Basic SQL Queries:
● SELECT - extracts data from a database
● UPDATE - updates data in a database
● DELETE - deletes data from a database
● INSERT INTO - inserts new data into a database
● CREATE DATABASE - creates a new database
● ALTER DATABASE - modifies a database
● CREATE TABLE - creates a new table
17
● ALTER TABLE - modifies a table
● DROP TABLE - deletes a table
● CREATE INDEX - creates an index (search key)
● DROP INDEX - deletes an index
Advantages of SQL:
● High Speed:
○ SQL Queries can be used to retrieve large amounts of records from a
database quickly and efficiently.
● Well Defined Standards Exist:
○ SQL databases use long-established standard, which is being adopted
by ANSI & ISO. Non-SQL databases do not adhere to any clear
standard.
● No Coding Required:
○ Using standard SQL it is easier to manage database systems without
having to write substantial amount of code.
● Emergence of ORDBMS:
○ Previously SQL databases were synonymous with relational database.
With the emergence of Object Oriented DBMS, object storage
capabilities are extended to relational databases.
Disadvantages of SQL:
● Difficulty in Interfacing:
○ Interfacing an SQL database is more complex than adding a few lines
of code.
● More Features Implemented in Proprietary way:
○ Although SQL databases conform to ANSI & ISO standards, some
databases go for proprietary extensions to standard SQL to ensure
vendor lock-in.
18
EXPERIMENT 3
Objective:
To get to know what an ER diagram is, what it’s components are, and how to draw
an ER diagram.
What is an ER Diagram?
An ER diagram is an Entity Relationship Diagram also known as Entity Relationship
Model. It i s a graphical representation of an information system that depicts the
relationships among people, objects, places, concepts or events within that system.
An ER Model is used to model the logical view of the system from data perspective
which consists of these components:
Attribute(s):
Attributes are the properties which define the entity type.
For example, Roll_No, Name, DOB, Age, Address, Mobile_No are the attributes
which defines entity type Student. In ER diagram, attribute is represented by an
oval.
Key Attribute –
The attribute which uniquely identifies each entity in the entity set is called key
attribute.
For example, Roll_No will be unique for each student. In ER diagram, k ey attribute
is represented by a n oval with underlying lines.
Composite Attribute –
An attribute composed of many other attribute is called as composite attribute.
For example, Address attribute of student Entity type consists of Street, City, State,
and Country. In ER diagram, composite attribute is represented by an o val
comprising of ovals.
Multivalued Attribute –
An attribute consisting more than one value for a given entity.
For example, Phone_No (can be more than one for a given student). In ER diagram,
multivalued attribute is represented by double oval.
Derived Attribute –
19
An attribute which can be derived from other attributes of the entity type is known
as derived attribute.
e.g.; Age (can be derived from DOB). In ER diagram, d erived attribute is
represented by dashed oval.
Relationship Type and Relationship Set:
A relationship type represents the association between entity types.
For example,‘Enrolled in’ is a relationship type that exists between entity type
Student and Course. In ER diagram, r elationship type is represented by a
diamond and connecting the entities with lines.
Degree of a relationship set:
The number of different entity sets participating in a relationship set is called as
degree of a relationship set.
● Unary Relationship – When there is only ONE entity set participating in a
relation, the relationship is called as unary relationship. For example, one
person is married to only one person.
● Binary Relationship – When there are TWO entities set participating in a
relation, the relationship is called as binary relationship.For example, Student
is enrolled in Course.
● n-ary Relationship – When there are n entities set participating in a relation,
the relationship is called as n-ary relationship.
Cardinality:
The number of times an entity of an entity set participates in a relationship set is
known as cardinality.
Cardinality can be of different types:
● One to one – When each entity in each entity set can take part only once in
the relationship, the cardinality is one to one. Let us assume that a male can
marry to one female and a female can marry to one male. So the relationship
will be one to one.
● Many to one – When entities in one entity set can take part only once in the
relationship set and entities in other entity set can take part more than once
in the relationship set, cardinality is many to one. Let us assume that a
student can take only one course but one course can be taken by many
students. So the cardinality will be n to 1. It means that for one course there
can be n students but for one student, there will be only one course.
● Many to many – When entities in all entity sets can take part more than
once in the relationship cardinality is many to many. Let us assume that a
20
student can take more than one course and one course can be taken by
many students. So the relationship will be many to many.
Example of ER Model:
1. College Management System
2. Employee Management System
21
EXPERIMENT 4
Objective:
To learn how to edit a table in SQL using queries
Problem Statement:
Create a table ‘Student’ with attributes — Roll Number, Name, Date of Birth, Phone
Number, Address and Course. Also, perform operations using INSERT, SELECT and
WHERE commands.
Explanation:
The various commands in the order in which they were used in the experiment are:
1. CREATE: This command is used to create a table
2. INSERT: This command is used to insert entries in a table, which may include
the values of all the attributes or just the selected ones.
3. SELECT: This command is used to select data from the database. Using this
command we can either select the entire table (SELECT * FROM table) or
chosen columns (SELECT Name FROM table).
4. WHERE: The where clause is used to filter records. This is used to filter only
those records which fulfill a specified condition.
OUTPUT:
Creation of Table :
Insertion of Entries:
22
CONCLUSION:
Here we learnt how to create a table and perform operations on it like
displaying an entry based on a condition on one of the attributes.
23
EXPERIMENT 5
Objective:
To learn how to multiple tables are connected via Foreign Key.
Problem statement:
Perform Queries on multiple tables, that is, a table ‘Course’ with the following
attributes — Course Code (unique identifier), Description, Duration, Level; and
another table ‘Student’ with the attributes — Roll Number, Name, Address, Phone
number, Course (Foreign Key related to Course Code of ‘Course’).
1. T
he total number of Under Graduate Students and Post Graduate Students
1. L
ist of Students in UG and PG Courses
2. L
ist of Students and their course Description for Students of Software
Engineering Department
3. L
ist of Students in a 2 year course from Software Engineering Department
Explanation:
A FOREIGN KEY is a column or group of columns in a relational database
table that provides a link between data in two tables.
The table containing the foreign key is called the child table, and the table
containing the candidate key is called the referenced or parent table.
24
3. SELECT - This command is used to select data from the database. Using
this command we can either select the entire table (SELECT * FROM
table) or chosen columns (SELECT Name FROM table).
4. WHERE - The where clause is used to filter records. This is used to filter
only those records which fulfill a specified condition.
6. COUNT(*) - T
he COUNT() function returns the number of rows that
matches a specified criteria.
7. INNER JOIN -The INNER JOIN keyword selects records that have
matching values in both tables.
Output:
Creation of Table Course1
25
26
27
28
List of Students in a 2 year course from Software Engineering Department
Conclusion:
In this experiment we learnt how to relate two tables and create a Foreign Key
referenced to an attribute of another table and display entries from both the tables
together as one table.
29
EXPERIMENT 6
Objective:
To get a better grasp of SQL by learning about new commands
Problem Statement:
1. ALL
2. ALTER TABLE
3. ANY
4. EXISTS
5. GROUP BY
6. FULL JOIN
7. LEFT JOIN
8. RIGHT JOIN
9. ORDER BY
10. UPDATE
ALL operator is used to select all tuples of SELECT statement. It is also used to
compare a value to every value in another value set or result from a subquery.
30
Here, it selected all the values in Student Table where CourseCode is ‘ECEUG’ and
displayed the Address column only.
2. A
LTER TABLE Command
ALTER TABLE is used to add, delete or modify columns in the existing table.
Here, Date of Birth column was added into the table and all the values are set to
NULL by default.
31
3. A
NY Operator
ANY compares a value to each value in a list or results from a query and evaluates
to true if the result of an inner query contains at least one row.
32
This operator displayed the records in the Course table that have Duration = ‘2
years’.
4. E
XISTS Condition
The EXISTS Condition in SQL is used to check whether the result of a correlated
nested query is empty or not.
This helped us fetch the name of the students whose CourseCode matched with
the CourseCode in the Course table.
5. G
ROUP BY Statement
33
The GROUP BY Statement in SQL is used to arrange identical data into groups with
the help of some functions It is used with the SELECT Statement.
For the table Student, we grouped the data into the Subjects and Year and also
displayed their count.
6. L
EFT JOIN Statement
The LEFT JOIN statement gives all rows in A, plus any common rows in B. If a record
in A doesn’t exist in B, it will return NULL for that row.
Here, since the last four tuples do not exist in the table Joining, their values for the
attributes Name, CourseID and Subject are NULL
34
7. R
IGHT JOIN Statement
The RIGHT JOIN statement gives all rows in table B, plus any common rows in A. If a
record in B doesn’t exist in A, it will return NULL for that row.
Here, the last three tuples have NULL values since those don’t exist in the table
Students.
8. F
ULL JOIN
MySQL does not support FULL JOIN, so we have to combine RIGHT JOIN, UNION,
LEFT JOIN to get an equivalent. It gives the results of A union B. It returns all records
from both tables. Those columns which exist only in one table will contain NULL in
the opposite table.
35
Here, the values that don’t exist in the other table have been given NULL values.
9. O
RDER BY Clause
The ORDER BY keyword sorts the records in ascending order by default. To sort the
records in descending order, use the DESC keyword.
36
The UPDATE Command is used to modify rows in a table. It can be used to update a
single field or multiple fields at the same time.
Conclusion:
Through this experiment, we learnt about the various Commands and
Conditions that can be performed in SQL, on Single and Multiple Tables.
37
EXPERIMENT 7
Objective: To get familiarized with the concept of nested/embedded queries
Problem Statement:
Create 2 tables Course and Student.
A Students can apply for only one course. The course details are in Course table
and the Student Table should contain a FOREIGN KEY to refer to the Primary Key of
Course table – “cid”.
• P opulate data into the tables and then perform the following using SQL
queries.
◦ F
ind Roll Numbers of All students living in Jaipur
◦ F
ind Courses where UG students are enrolled
◦ F
ind Roll Number of all students in UG level
◦ F
ind Contact Number of all students of course DBMS.
Explanation:
Subqueries provide an easy and efficient way to handle the queries that depend on
the results from another query.
A Subquery or Inner query or a Nested query is a query within another SQL query
and embedded within the WHERE clause.
A subquery is used to return data that will be used in the main query as a condition
to further restrict the data to be retrieved.
Subqueries can be used with the SELECT, INSERT, UPDATE and DELETE statements
along with the operators like =, <, >, <=, >=, IN, BETWEEN, etc.
Output:
Display of ‘Student1’ Table
38
39
40
Address of Students in Course Computer Engg-UG
CONCLUSION:
We learnt about Nested/Embedded Sub-queries.
41
42