DBMS 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Database Management System

Questions
Q.No.
Explain the component modules of DBMS and their interaction, with help of a diagram

Solution :

➢ DDL compiler-processes schema definitions, specified in the DDL, and stores descriptions
of the schemas (meta-data) in the DBMS catalogue .
➢ Interactive query interface: interface for Casual users and persons with occasional need
for information from the database.
➢ Query compiler- validates for correctness of the query syntax, the names of files and data
elements & compiles them into an internal form.
Describe the characteristics of Database approach

Solution :

The main characteristics of the database approach versus the file-processing approach are the
following:
• Self-describing nature of a database system
• Insulation between programs and data, and data abstraction
2 • Support of multiple views of the data
• Sharing of data and multiuser transaction processing

1. Self-Describing Nature of a Database System

➢ The fundamental characteristic of database approach is that it has a complete definition or


description of the database.
➢ The complete definition or description of the database structures & constraints are known as
meta-data.
➢ Meta-data is stored in so-called system catalog.
➢ The description of the db file contains the type, storage format of each field and conditions
that data must satisfy.
➢ The system catalog is also used by the DBMS software to know how the data is structured
and organize it well.

2. Insulation between programs , data and data abstraction


➢ Program-Data Independence :
• In file processing approach , the structure of the db files accessed by an
application is “hard-coded” in its source code. Due to this the upgradability of
the db files were difficult.
• So, in DBMS approach the structure of the data is described separately from the
programs that access it.
• While accessing the data, these programs refer the catalog to access the structure
of the data.
• The DBMS approach makes way for easier upgradability of the features of the db
file, without harming the data stored in it.
➢ Program-operation independence :
• In Object-oriented systems, users can define operations on data as part of the
database definitions.
• An operation is specified into 2 parts : 1.Interface , 2. Implementation.
• The interface (or signature) of an operation includes the operation name and
the data types of its arguments.
• The implementation (or method) of the operation is specified separately and
can be changed without affecting interface.
• User application programs can operate on the data by invoking these operations.
➢ Data Abstraction :
• The characteristic that allows program-data independence and program-operation
independence is called data abstraction.
• DBMS provides the conceptual view of data to the users rather than showing its
implementation.
• A data model is a type of data abstraction that is used to provide this conceptual
representation.
• This model uses logical concepts like objects, their properties and
interrelationships.

3. Support of Multiple Views of the Data


➢ Each user may have a different perspective or view of the data in the db file.
➢ A multiuser DBMS whose users have a variety of distinct applications must provide
facilities for defining multiple views.
➢ A view may be a subset of the database or it may contain the virtual data derived from
the database.
➢ This feature helps in preventing the production of redundant data for each user.

4. Sharing of Data and Multiuser Transaction Processing

➢ A multiuser DBMS, must allow multiple users to access the database at the same time.
Because the same database can be connected to multiple applications.
➢ The DBMS must include concurrency-control software to synchronize the access
requests of multiple users.
➢ These type of tasks are usually performed in applications such as bookmyshow, yono
SBI, IRCTC booking app, etc.
➢ These types of applications are generally called as online transaction
processing(OLTP) applications.
➢ A fundamental role of multiuser DBMS software is to ensure that concurrent transactions
operate correctly and efficiently.
Explain types of end-users with suitable examples

Solution :
End Users:
These are persons who access the database for querying, updating, and
report generation. There are several categories of end users :
• Casual end users: use database occasionally, needing different information each time; use
query language to specify their requests; typically middle- or high-level managers.

• Naive/Parametric end users: biggest group of users; frequently query/update the database
using standard canned transactions that have been carefully programmed and tested in
advance. Examples:
3
➢ bank tellers check account balances, post withdrawals/deposits
➢ reservation clerks for airlines, hotels, etc., check availability of seats/rooms and
make reservations.

• Sophisticated end users: includes engineers, scientists, business analysts, and others who
thoroughly familiarize themselves with the facilities of the DBMS in order to implement
their own applications to meet their complex requirements.

• Stand-alone users: maintain personal databases by using ready-made program packages that
provide easy-to-use menu-based or graphics-based interfaces.
➢ Ex: user of a tax package that stores a variety of personal financial data for tax
purposes.
Write the ER diagram for an employee database. The constraints are as follows:
i) An employee works for a department
ii) Every department is headed by a manager
iii) An employee works on one or more projects
4
iv) An employee has dependents
v) A department controls the projects

Solution :
List and explain the advantages of using DBMS

Solution :
1. Controlling Redundancy :
5 • Data redundancy such as tends to occur in the "file processing" approach leads to
wasted storage space, duplication of effort and a higher likelihood of the introduction
of inconsistency.
• In the database approach, the views of different user groups are integrated during
database design. This is known as data normalization, and it ensures consistency and
saves storage Space. However, it is sometimes necessary to use controlled
redundancy to improve the performance of queries.

2. Restricting Unauthorized Access :


• When multiple users share a large database, it is likely that most users will not be
authorized to access all information in the database.
• For example, financial data is often considered confidential and only authorized
persons are allowed to access such data.
• A DBMS should provide a security and authorization subsystem, which the DBA
uses to create accounts, to specify account restrictions and enforce these restrictions
automatically.

3. Providing Persistent Storage for Program Objects :


• The values of program variables or objects are discarded once a program terminates,
unless the programmer explicitly stores them in permanent files, which often involves
converting these complex structures into a format suitable for file storage.
• Object-oriented database systems make it easier for complex runtime objects to be
saved in secondary storage so as to survive beyond program termination and to be
retrievable at a later time.
• Object-oriented database systems are compatible with programming languages such
as C++ and Java, and the DBMS software automatically performs any necessary
conversions.

4. Providing Storage Structures and Search Techniques for Efficient Query Processing :
• DBMS maintains indexes that are utilized to improve the execution time of queries
and updates.
• DBMS has a buffering or caching module that maintains parts of the database in
main memory buffers.
• The query processing and optimization module is responsible for choosing an
efficient query execution plan for each query submitted to the system.

5. Providing Backup and Recovery :


• The backup and recovery subsystem of the DBMS is responsible for recovery.
• For example, if the computer system fails in the middle of a complex update
transaction, the recovery subsystem is responsible for making sure that the database
is restored to the state it was in before the transaction started executing.
• Disk backup is also necessary in case of a catastrophic disk failure.

6. Providing Multiple User Interfaces :


• Because many types of users with varying levels of technical knowledge use a
database, a DBMS should provide a variety of user interfaces.
• These include –
➢ Query languages for casual users
➢ Programming language interfaces for application programmers
➢ Forms and command codes for parametric users
➢ Menu-driven interfaces and natural language interfaces for standalone users.

7. Representing Complex Relationships among Data :


• A database may include numerous varieties of data that are interrelated in many
ways.
• For example each section record is related to one course record and to a number of
GRADE_REPORT records one for each student who completed that section.

8. Enforcing Integrity Constraints :


• The simplest type of integrity constraint involves specifying a data type for each data
item.
• More complex type of constraint is referential integrity involves specifying that a
record in one file must be related to records in other files. For example, in university
database, we can specify that every section record must be related to a course record.
• Another type of constraint specifies uniqueness on data item values, such as every
course record must have a unique value for Course_number. This is known as a key
or uniqueness constraint.
• For example, in student table we specified that the value of Name must be a string of
no more than 30 alphabetic characters.

9. Permitting Inferencing and Actions Using Rules :


• In a deductive database system, one may specify declarative rules that allow the
database to infer new data.
• For example, figure out which students are on academic probation. Such capabilities
would take the place of application programs that would be used to ascertain such
information otherwise.
• Active database systems go one step further by allowing "active rules" that can be
used to initiate actions automatically.

10. Additional Implications Of Using the Database Approach :


• Potential for Enforcing Standards :
➢ database approach permits the DBA to define and enforce standards among
database users in a large organization which facilitates communication and
cooperation among various departments, projects, and users within the
organization.
• Reduced Application Development Time :
➢ once a database is up and running, substantially less time is generally required
to create new applications using DBMS facilities.
• Flexibility :
➢ It may be necessary to change the structure of a database as requirements
change.
• Availability of Up-to-Date Information :
➢ Availability of up-to-date information is essential for many transaction-
processing applications, such as reservation systems or banking databases
• Economies Of Scale :
➢ DBMS approach permits consolidation of data and applications, to overlap
between activities of data-processing in different projects or departments.
Explain three schema architecture . Why do we need mappings between schema levels
6
Solution :
The Three-Schema Architecture

The goal of the three-schema architecture is to separate the user applications from the physical
database. In this architecture, schemas can be defined at the following three levels:

1. The internal level has an internal schema, which describes the physical storage
structure of the database. The internal schema uses a physical data model and describes the
complete details of data storage and access paths for the database.

2. The conceptual level has a conceptual schema, which describes the structure of the whole
database for a community of users. The conceptual schema hides the details of physical
storage structures and concentrates on describing entities, data types, relationships, user
operations, and constraints. Usually, a representational data model is used to describe the
conceptual schema when a database system is implemented.

3. The external or view level includes a number of external schemas or user views. Each
external schema describes the part of the database that a particular user group is interested in
and hides the rest of the database from that user group. Each external schema is typically
implemented using a representational data model, possibly based on an external schema
design in a high-level data model.

➢ Hence, the DBMS must transform a request specified on an external schema into a
request against the conceptual schema, and then into a request on the internal schema for
processing over the stored database.

➢ The processes of transforming requests and results between levels are called mappings.

Explain the relational algebra operations from Set Thoery, with example.
Solution :
➢ UNION: The result of this operation, denoted by R ∪ S, is a relation that includes all tuples
that are either in R or in S or in both R and S. Duplicate tuples are eliminated.
7 ➢ INTERSECTION: The result of this operation, denoted by R ꓵ S, is a relation that includes
all tuples that are in both R and S.
➢ SET DIFFERENCE (or MINUS): The result of this operation, denoted by R - S, is a
relation that includes all tuples that are in R but not in S.
Note :
• Selection(σ): It is used to select required tuples of the relations.
• Projection(π): It is used to project required column data from a relation.

Example: Consider the the following two relations: STUDENT & INSTRUCTOR
Single relational algebra expression:

• UNION, INTERSECTION and SET DIFFERENCE are binary operations; that is, each is
applied to two sets (of tuples).
• When these operations are adapted to relational databases, the two relations on which any of
these three operations are applied must have the same type of tuples; this condition has been
called union compatibility or type compatibility.

➢ Both UNION and INTERSECTION obey commutative law :

➢ Both UNION and INTERSECTION obey associative law, they can be applicable to n-ary
operations :

➢ MINUS is not commutative :

➢ Intersection can be expressed in terms of union and set differences as follows :

THE CARTESIAN PRODUCT (CROSS PRODUCT) OPERATION :

➢ The CARTESIAN PRODUCT operation also known as CROSS PRODUCT or CROSS


JOIN denoted by × is a binary set operation, but the relations on which it is applied do
not have to be union compatible.
➢ This set operation produces a new element by combining every member (tuple) from one
relation (set) with every member (tuple) from the other relation (set).
➢ In general, the result of R(A1, A2, ……, An) x S(B1, B2, …. , Bm) is a relation Q with
degree n+m attributes Q(A1,A2, ….., An, B1, B2, …., Bm), in the order.
➢ The resulting relation Q has one tuple for each combination of tuples one from R and
one from S. Hence, if R has n R tuples (denoted as |R| = n R ), and S has nS tuples, then
R × S will have n R * n S tuples.

Example :
➢ In SQL, CARTESIAN PRODUCT can be realized by using the CROSS JOIN option in
joined tables .
Given the schema :
Passenger(pid, pname, pgender, pcity)
Agency(aid, aname,acity)
Flight(fid,fdate,time,src,dest)
Booking(pid, aid,fid, fdate)
Identify and write relation algebra expression for the following:
i) Get the complete details of all flights to New Delhi

Result = π_fid, fdate, time, src, dest (σ_dest='New Delhi'(Flight))

ii) Find only the flight numbers for passenger with pid 123 for flights to Chennai before
06/11/2020
8
Result = π_fid (σ_pid=123 and dest='Chennai' and fdate<'06/11/2020'(Booking ⨝
Flight))

iii) Find the passenger names for those who do not have any bookings in any flights

Result = π_pname (Passenger - π_pname (Passenger ⨝ Booking))

iv) Get the details of flights that are scheduled on both dates 01/12/2020 and 02/12/2020 at
16:00 hours

Result = π_fid, fdate, time, src, dest (σ_fdate='01/12/2020' and time='16:00' (Flight
⨝ ρ_fdate2,fid2,time2,src2,dest2(σ_fdate='02/12/2020' and time='16:00' (Flight))))
v) Find the details of all male passengers who are associated with jet agency

Result = π_pid, pname, pgender, pcity (σ_pgender='Male' and aname='Jet Agency'


(Passenger ⨝ Booking ⨝ Agency))
Explain the different Relational model Constraints.
9
Solution :

Identify and write SQL query for the following database schema:
Employee(employee_name, street, city)
Works(employee_name,company_name,salary)
Company(company_name, city)
Manages(employee_name, manager_name)
i) Find the names, street address, and cities of residence for all employees who work for 'First
Bank Corporation' and earn more than $10,000.

SELECT E.employee_name, E.street, E.city


FROM Employee E
JOIN Works W ON E.employee_name = W.employee_name
WHERE W.company_name = 'First Bank Corporation' AND W.salary > 10000;

ii) Find the names of all employees in the database who do not work for 'First Bank Corporation'.
Assume that all people work for exactly one company.

SELECT employee_name
FROM Employee
WHERE employee_name NOT IN (SELECT employee_name FROM Works WHERE
company_name = 'First Bank Corporation');

iii) Find the names of all employees in the database who earn more than every employee of 'Small
10
Bank Corporation'. Assume that all people work for at most one company.

SELECT E.employee_name
FROM Employee E
JOIN Works W1 ON E.employee_name = W1.employee_name
WHERE W1.salary > ALL (SELECT W2.salary FROM Works W2 WHERE
W2.company_name = 'Small Bank Corporation');

iv) Find the name of the company that has the smallest payroll.

SELECT company_name
FROM Works
GROUP BY company_name
ORDER BY SUM(salary)
LIMIT 1;

v) Find the names of all employees in the database who live in the same cities and on the same
streets as do their managers.

SELECT E.employee_name
FROM Employee E
JOIN Manages M ON E.employee_name = M.employee_name
JOIN Employee Mgr ON M.manager_name = Mgr.employee_name AND E.city =
Mgr.city AND E.street = Mgr.street;

Explain the entity integrity and referential integrity constraints. Why is each considered important.
11
Give Examples.
12 Explain the ER to relational mapping algorithm with suitable example for each step

You might also like