Question Bank DBMS
Question Bank DBMS
Database management system is a software which is used to manage the database. For example:
MySQL, Oracle, etc are a very popular commercial database which is used in different applications.
DBMS provides an interface to perform various operations like database creation, storing data in it,
updating data, creating a table in the database and a lot more.
It provides protection and security to the database. In the case of multiple users, it also maintains data
consistency.
Advantages of DBMS
Controls database redundancy: It can control data redundancy because it stores all the data in one
single database file and that recorded data is placed in the database.
Data sharing: In DBMS, the authorized users of an organization can share the data among multiple
users.
Easily Maintenance: It can be easily maintainable due to the centralized nature of the database system.
Reduce time: It reduces development time and maintenance need.
Backup: It provides backup and recovery subsystems which create automatic backup of data from
hardware and software failures and restores the data if required.
multiple user interface: It provides different types of user interfaces like graphical user interfaces,
application program interfaces
Controls database redundancy: It can control data redundancy because it stores all the data in one
single database file and that recorded data is placed in the database.
Data sharing: In DBMS, the authorized users of an organization can share the data among multiple users.
Easily Maintenance: It can be easily maintainable due to the centralized nature of the database system.
Reduce time: It reduces development time and maintenance need.
Backup: It provides backup and recovery subsystems which create automatic backup of data from
hardware and software failures and restores the data if required.
multiple user interface: It provides different types of user interfaces like graphical user interfaces,
application program interfaces.
A database management system is able to store any kind of data in a database.
The database management system has to support ACID (atomicity, consistency, isolation, durability)
properties.
The Database management system allows so many users to access databases at the same time.
Backup and recovery are the two main methods which allow users to protect the data from damage or
loss.
It also provides multiple views for different users in a single organization.
It follows the concept of normalization which is helpful to minimize the redundancy of a relation.
It also provides users query language, helpful to insert, retrieve, update, and delete the data in a
database.
Entity-Relationship Approach
Strong Entity:
A strong entity is not dependent on any other entity in the schema. A strong entity will always have a
primary key. Strong entities are represented by a single rectangle. The relationship of two strong entities
is represented by a single diamond.
Various strong entities, when combined together, create a strong entity set.
Weak Entity:
A weak entity is dependent on a strong entity to ensure its existence. Unlike a strong entity, a weak entity
does not have any primary key. It instead has a partial discriminator key. A weak entity is represented by
a double rectangle.
The relation between one strong and one weak entity is represented by a double diamond. This
relationship is also known as identifying relationship.
For example, suppose we design a school database. In this database, the student will be an entity with attributes
like address, name, id, age, etc. The address can be another entity with attributes like city, street name, pin code,
etc and there will be a relationship between them.
Component of ER Diagram
Entity:
An entity may be any object, class, person or place. In the ER diagram, an entity can be represented as
rectangles.
Consider an organization as an example- manager, product, employee, department etc. can be taken as an
entity.
Weak Entity
An entity that depends on another entity called a weak entity. The weak entity doesn't contain any key attribute of
its own. The weak entity is represented by a double rectangle.
Attribute
The attribute is used to describe the property of an entity. Eclipse is used to represent an attribute.
For example, id, age, contact number, name, etc. can be attributes of a student.
Composite Attribute
An attribute that composed of many other attributes is known as a
composite attribute. The composite attribute is represented by an ellipse,
and those ellipses are connected with an ellipse.
Multivalued Attribute
An attribute can have more than one value. These attributes are known as a
multivalued attribute.
The double oval is used to represent multivalued attribute.
For example, a student can have more than one phone number.
Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute. It
can be represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from another
attribute like Date of birth.
Relationship
Various Types Of Table Relationships
A relationship is used to describe the relation between
entities. Diamond or rhombus is used to represent the
relationship.
One-to-One Relationship
When only one instance of an entity is associated with the relationship, then it is known as one to one
relationship.
One-to-many relationship
When only one instance of the entity on the left, and more than one instance of an entity on the right associates
with the relationship then this is known as a one-to-many relationship.
For example,
Many-to-one relationship
When more than one instance of the entity on the left, and only one instance of an entity on the right associates
with the relationship then it is known as a many-to-one relationship.
For example, If there are two entity type ‘Customer’ and ‘Account’ then each ‘Customer’ can have more than one
‘Account’ but each ‘Account’ is held by only one ‘Customer’. In this example, we can say that each Customer is
associated with many Account. So, it is a one-to-many relationship. But, if we see it the other way i.e many
Account is associated with one Customer then we can say that it is a many-to-one relationship.
Many-to-many relationship
When more than one instance of the entity on the left, and more than one instance of an entity on the right
associates with the relationship then it is known as a many-to-many relationship.
A query is a request for data or information from a database table or combination of tables. This data may
be generated as results returned by Structured Query Language (SQL) or as pictorials, graphs or complex results,
These commands are used to update the database schema that's why they come under Data definition language.
Aggregate functions: Aggregate functions in DBMS take multiple rows from the table and return a value
according to the query.
AVG – calculates the average of a set of values.
COUNT – counts rows in a specified table or view.
MIN – gets the minimum value in a set of values.
MAX – gets the maximum value in a set of values.
SUM – calculates the sum of values
Examples:
Now let us understand each Aggregate function with a
Id Name Salary
1 A 80
2 B 40
3 C 60
4 D 70
5 E 60
6 F Null
Count():
Count(*): Returns total number of records .i.e 6.
Count(salary): Return number of Non Null values over the column salary. i.e 5.
Count(Distinct Salary): Return number of distinct Non Null values over the column salary .i.e 4
Sum():
sum(salary): Sum all Non Null values of Column salary i.e., 310
sum(Distinct salary): Sum of all distinct Non-Null values i.e., 250
Avg():
Avg(salary) = Sum(salary) / count(salary) = 310/5
Avg(Distinct salary) = sum(Distinct salary) / Count(Distinct Salary) = 250/4
Min():
Min(salary): Minimum value in the salary column except NULL i.e., 40.
Max()
Max(salary): Maximum value in the salary i.e., 80.
DBMS Architecture
The DBMS design depends upon its architecture. The basic client/server architecture is used to deal with
a large number of PCs, web servers, database servers and other components that are connected with
networks.
The client/server architecture consists of many PCs and a workstation which are connected via the
network.
DBMS architecture depends upon how users are connected to the database to get their request done.
The 2-Tier architecture is same as basic client-server. In the two-tier architecture, applications on the client end
can directly communicate with the database at the server side. For this interaction, API's like: ODBC, JDBC are
used.
The user interfaces and application programs are run on the client-side.
The server side is responsible to provide the functionalities like: query processing and transaction
management.
To communicate with the DBMS, client-side application establishes a connection with the server side.
Tier Architecture
The 3-Tier architecture contains another layer between the client and server. In this architecture, client can't
directly communicate with the server.
The application on the client-end interacts with an application server which further communicates with
the database system.
End user has no idea about the existence of the database beyond the application server. The database also
has no idea about any other user beyond the application.
The 3-Tier architecture is used in case of large web application.
The concept of Schemas and Instance
Schema:
The overall design of the database is called database schema. Schema will not be changed frequently. It is the
logical structure of a database. It does not show the data in the database.
Types of Schema
Physical schema − It is a database design at the physical level.It is hidden below the logical schema and can be
changed easily without affecting the application programs.
Logical schema − It is a database design at the logical level. Programmers construct applications using logical
schema.
External − It is schema at view level. It is the highest level of a schema which defines the views for end users.
Generally the Database Management System (DBMS) assists one physical schema, one logical schema and
several sub or external schemas.
Database schema refers to the format and layout of the database in which the data will be stored. It is the one
thing that remains the same throughout unless otherwise modified. It defines the structure of what type of data and
how it will be stored.
Example
A database schema for a person will have fields for name, email, phone and address as shown below −
Person
Instance
Instance or extension or database state is a collection of information that stored in a database at a particular
moment is called an instance of the database. The Database instance refers to the information stored in the
database at a given point of time. Thus, it is a dynamic value which keeps on changing.
Example
A database instance for the Person database can be (User1,emai.com,11345679,addr) So the person construct will
contain their individual entities in the attributes called as instance. This is shown below −
Person
Name Email Phone no
BOB [email protected] 2343435
JANU [email protected] 5345464
PRIYA [email protected] 2342342
Conventional Modeling
Data Models
Data models are a methods by which data is structured to represent the real world and the manner in which the
data is accessed. These models provide alternative ways of picturing the relationships and serve as frameworks for
mapping the conceptual schema of a database.
Data Models in DBMS are:
Hierarchical Model.
Network Model.
Entity-Relationship Model.
Relational Model.
Object-Oriented Data Model.
Object-Relational Data Model.
Flat Data Model.
Semi-Structured Data Model.
A hierarchical database is a set of tables arranged in the form of a parent-child relationship. Each set of parents
can have a relationship with any number of children. But every child can have a relationship with only one set of
parents.
Hierarchical database model offers the following advantages:
The model allows you to easily add and delete new
information.
Data at the top of the hierarchy can be accessed quickly.
This model works well with linear data storage mediums such
as tapes.
It supports systems that work through a one-to-many
relationship. For instance, there’s a president with many
managers below them, and those managers have many
employees below them, but each employee has only one
manager.
The concept Network Model :
This model is the generalization of the hierarchical model. This model can consist of multiple parent segments
and these segments are grouped as levels but there exists a logical association between the segments belonging to
any level. Mostly, there exists a many-to-many logical association between any of the two segments
The network database model was created to solve the shortcomings of the hierarchical database model. In this
type of model, a child can be linked to multiple parents, a feature that was not supported by the hierarchical data
model. The parent nodes are known as owners and the child nodes are
called members.
The network database model is a model for modeling the entities in
such a way that one child entity can have more than one parent entity.
In this figure, we can see that the subject is the child class and student and degree are the parent classes.
So, the subject has two parent classes. STUDENT has one child and the Degree class also have one child. This
kind of relationship among entities represents the network model.
Relational Calculus
Relational calculus is a non-procedural query language. In the non-procedural query language, the user is
concerned with the details of how to obtain the end results.
The relational calculus tells what to do but never explains how to do.
Notation:
For example:
OUTPUT: This query selects the tuples from the AUTHOR relation. It returns a tuple with 'name' from Author
who has written an article on 'database'.
TRC (tuple relation calculus) can be quantified. In TRC, we can use Existential (∃) and Universal Quantifiers (∀).
For example:
Notation:
1. { a1, a2, a3, ..., an | P (a1, a2, a3, ... ,an)}
Where
a1,a2 are attributes
P stands for formula built by inner attributes
For example:
{< article, page, subject > | ∈ javatpoint 𝖠 subject = 'database'}
Output: This query will yield the article, page, and subject from the relational javatpoint, where the subject is a
database.
----------------- ------------------------- ---------------------- --------------------------------- -- ------------------------
Normalization
Normalization is the process of organizing data in a database. This includes creating tables and establishing
relationships between those tables according to rules designed both to protect the data and to make the database
more flexible by eliminating redundancy and inconsistent dependency
Database Normalization with Examples: Database Normalization is organizing non structured data in to structured
data. Database normalization is nothing but organizing the tables and columns of the tables in such way that it
should reduce the data redundancy and complexity of data and improves the integrity of data.
Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form on strict terms. BCNF states that
−
Boyce-Codd Normal Form (BCNF) is one of the forms of database normalization. A database table is in BCNF if
and only if there are no non-trivial functional dependencies of attributes on anything other than a superset of a
candidate key. BCNF is also sometimes referred to as 3.5NF, or 3.5 Normal Form
In the above image, Stu_ID is the super-key in the relation Student_Detail and Zip is the super-key in the relation
ZipCodes. So,
Stu_ID → Stu_Name, Zip and
Zip → City
Functional Dependency
A functional dependency is a constraint between two sets of attributes from the database. A functional
dependency, represented by X → Y, between two sets of attributes X and Y that are subsets of a relation R
specifies a constraint that, for any two tuples t1 and t2 in R that have t1[X] = t2[X],they must also have t1[Y] =
t2[Y].
This means the values of the set of attributes Y of a tuple in R are determined by the set of attributes X. In other
words, the values of the set of attributes X functionally determine the values of the set of attributes Y. We can
also say that Y is functionally dependent on Y.
The set of attributes X on the left-hand side of the functional dependency is called determinant and the set of
attributes Y on the right-hand side of the functional dependency is called dependent.
Consider the example of an SSN (Social Security Number) database. Every individual has a unique SSN. So, the
other attributes of the relation, like name, address etc. can be determined using the SSN. That makes SSN a
determinant, and name, address, the dependents – thus establishing the functional dependencies:
SSN → name
SSN → address
A hierarchical direct (HD) database is a database that maintains the hierarchical sequence of its segments by
having segments point to one another (inste databases that use a randomizing module are referred to as
hierarchical direct access method (HDAM) databases. HD databases that use a primary index are referred to as
hierarchical indexed direct access method (HIDAM) databases. HD databases can also be partitioned.
HDAM (Hierarchical Direct Access Method). Root segments are inserted by applying a randomizing routine to
the sequence field. The value computed assigns a storage location to the segment. Root segments are retrieved by
applying the same hash code. Descendant segments are stored independently and linked by pointers. Since the
roots are stored in a random physical sequence without an index, they cannot be accessed sequentially in root key
order.
HIDAM (Hierarchical Indexed Direct Access Method). The database consists of two parts, the data database and
a separate database that is an index on the sequence field of the root segment. The data database is physically
loaded in hierarchical sequence. Roots can be accessed sequentially or directly, but each direct access requires
reading the index database prior to reading the data database. Root sequence fields must be unique. That is, no
two root segment instances can contain the same key value.
HDAM
HD databases are stored on direct-access devices in either a VSAM ESDS or an OSAM data set. In most cases,
each segment in an HD database has one or more direct-address pointers in its prefix.
When direct-address pointers are used, database records and segments can be stored anywhere in the database.
After segments are inserted into the database, they remain in their original positions unless the segments are
deleted or until the database is reorganized.
During database update activity, pointers are updated to reflect the hierarchical relationships of the segments.
HD databases also differ from sequentially organized databases because space in HD databases can be reused.
HIDAM
In HIDAM databases, the primary index is a database that IMS™ loads and maintains. In PHIDAM databases, the
primary index is a data set that IMS loads and maintains.
The advantage of a randomizing module is that the I/O operations that are required to search an index are
eliminated. In PHDAM and PHIDAM databases, before IMS uses either the randomizing module or the primary
index, IMS must determine which partition the root segments are stored in by using a process called partition
selection.
Elaborate the role of locking technique.
A lock is a data variable which is associated with a data item. This lock signifies that operations that can
be performed on the data item. Locks in DBMS help synchronize access to the database items by concurrent
transactions. All lock requests are made to the concurrency-control manager
Locking protocols are used in database management systems as a means of concurrency control. Multiple
transactions may request a lock on a data item simultaneously. Hence, we require a mechanism to manage the
locking requests made by transactions. Such a mechanism is called as Lock Manager.
Database systems equipped with lock-based protocols use a mechanism by which any transaction cannot
read or write data until it acquires an appropriate lock on it. Locks are of two kinds −
Binary Locks − A lock on a data item can be in two states; it is either locked or unlocked.
Shared/exclusive − This type of locking mechanism differentiates the locks based on their uses. If a lock is
acquired on a data item to perform a write operation, it is an exclusive lock. Allowing more than one transaction
to write on the same data item would lead the database into an inconsistent state. Read locks are shared because
no data value is being changed.
Lock in SQL
Locks are held on SQL Server resources, such as rows read or modified during a transaction, to prevent
concurrent use of resources by different transactions. For example, if an exclusive (X) lock is held on a row
within a table by a transaction, no other transaction can modify that row until the lock is released.
Lock:
A lock is a data variable which is associated with a data item.
This lock signifies that operations that can be performed on the
data item. Locks in DBMS help synchronize access to the database
items by concurrent transactions. All lock requests are made to
the concurrency-control manager.there is one lock for each data item in the database.
Database systems, like any other computer system, are subject to failures but the data stored in it must be
available as and when required. When a database fails it must possess the facilities for fast recovery. It must also
have atomicity i.e. either transactions are completed successfully and committed (the effect is recorded
permanently in the database) or the transaction should have no effect on the database.
A catastrophic failure is one where a stable, secondary storage device gets corrupt. With the storage device, all the
valuable data that is stored inside is lost.
Database recovery :
Database recovery is the process of restoring the database to a correct (consistent) state in the event of a
failure. In other words, it is the process of restoring the database to the most recent consistent state that
existed shortly before the time of system failure.
There are four different recovery techniques are available in the Database.
Mirroring.
Recovery using Backups.
Recovery using Transaction Logs.
Shadow Paging.