RDBMS Important Questions With Answers
RDBMS Important Questions With Answers
It is a software that is used to define create and maintain a database and provides controlled accessed
to the data . RDBMS is an advanced version or extension of a DBMS
Information is RDBMS is in tables and the data sharing between tables is called relation
Eg: student number name address phone nmber father name etc
dodnot store repeated data with out duplication & stored in the centralized unit and acesed by , more
than one person can acess the data from a data base multiple users
Create database
Insert data in to a DB
To modify data in a DB
To maintain a DB
UNIT – I
Information
Information can be defined as processed data that increases the knowledge of end user.
Information is used to reveal the meaning of data.
Good, accurate and timely information is used in decision making.
The quality of data influences the quality of information.
Information can be presented in the tabular form, bar graph or an image.
Database :
Database can be defined as organized collection of logically related data.
Database can be of any size and complexity.
Data are structured so as to be easily stored, manipulated, and retrieved by users.
Example: Sales person can store customers contacts on his laptop that consist of few mega
bytes of data or A big company can store the data of all activities in the organization which
helps in decision making..
DBMS:
Database management system can be defined as reorganized collection of logically related data and
set of programs used for creating, storing, updating and retrieval of data from the database.
DBMS acts as a mediator between end-user and the database.
Database management system (DBMS): can be defined as collection of programs
Database Systems
• Database system consists of logically related data stored in a single logical data repository.
• Database system may be physically distributed among multiple storage facilities
• DBMS eliminates most of file system’s problems.
• Current generation stores data structures, relationships between structures, and access paths. Also
defines, stores, and manages all access paths and components
TYPES OF DATABASES
• Databases can be classified according to:
– Number of users
– Database location(s)
– Expected type and extent of use
• Single-user database supports only one user at a time
– Desktop database: single-user; runs on PC
• Multiuser database supports multiple users at the same time
– Workgroup and enterprise databases
• Centralized database: data located at a single site
• Distributed database: data distributed across several different sites
• Operational database: supports a company’s day-to-day operations
– Transactional or production database
• Data warehouse: stores data used for tactical or strategic decisions
Data redundancy and inconsistency: Redundancy is the concept of repetition of data i.e.
each data may have more than a single copy. The file system cannot control the redundancy
of data as each user defines and maintains the needed files for a specific application to run.
There may be a possibility that two users are maintaining the data of the same file for
different applications. Hence changes made by one user do not reflect in files used by
second users, which leads to inconsistency of data. Whereas DBMS controls redundancy by
maintaining a single repository of data that is defined once and is accessed by many users.
As there is no or less redundancy, data remains consistent.
Data sharing: The file system does not allow sharing of data or sharing is too complex.
Whereas in DBMS, data can be shared easily due to a centralized system.
Data concurrency: Concurrent access to data means more than one user is accessing the
same data at the same time. Anomalies occur when changes made by one user get lost
because of changes made by another user. The file system does not provide any procedure
to stop anomalies. Whereas DBMS provides a locking system to stop anomalies to occur.
Data searching: For every search operation performed on the file system, a different
application program has to be written. While DBMS provides inbuilt searching operations.
The user only has to write a small query to retrieve data from the database.
Data integrity: There may be cases when some constraints need to be applied to the data
before inserting it into the database. The file system does not provide any procedure to
check these constraints automatically. Whereas DBMS maintains data integrity by enforcing
user-defined constraints on data by itself.
System crashing: In some cases, systems might have crashed due to various reasons. It is
a bane in the case of file systems because once the system crashes, there will be no
recovery of the data that’s been lost. A DBMS will have the recovery manager which
retrieves the data making it another advantage over file systems.
Data security: A file system provides a password mechanism to protect the database but
how long can the password be protected? No one can guarantee that. This doesn’t happen
in the case of DBMS. DBMS has specialized features that help provide shielding to its data.
Backup: It creates a backup subsystem to restore the data if required.
Interfaces: It provides different multiple user interfaces like graphical user interface and
application program interface.
Easy Maintenance: It is easily maintainable due to its centralized nature.
DBMS is continuously evolving from time to time. It is a powerful tool for data storage and
protection. In the coming years, we will get to witness an AI-based DBMS to retrieve databases
of ancient eras.
Database approach:
An information system that uses a Database
Management System (DBMS) to manage its
information has a particular structure, comprising three
components: Data, DBMS, and Application software.
This structure as described below is referred to as the
database approach to information system
development.
The central component of the database approach is the
DBMS. This software is also referred to as the
“database engine” or the “back end.” With regard to
the data it manages, it has several responsibilities
including the following:
Consider an example of a student's file system. The student file will contain
information regarding the student (i.e. roll no, student name, course etc.).
Similarly, we have a subject file that contains information about the subject
and the result file which contains the information regarding the result.
Some fields are duplicated in more than one file, which leads to data
redundancy. So to overcome this problem, we need to create a centralized
system, i.e. DBMS approach.
DBMS:
There are the following differences between DBMS and File systems:
There is no
Efficient query
efficient query
processing is
processing in the
Query there in DBMS.
processing file system.
There is more
There is less data data consistency
consistency in the because of the
file system. process of
Consistency normalization.
It has more
It is less complex complexity in
as compared to handling as
DBMS. compared to the
Complexity file system.
It has a
It is less expensive comparatively
than DBMS. higher cost than a
Cost file system.
In DBMS data
independence
exists, mainly of
There is no data two types:
independence. 1) Logical Data
Independence.
2)Physical Data
Data
Independence Independence.
databases
Data is distributed
Due to centralized
in many files. So, it
nature data
is not easy to
sharing is easy
Sharing share data.
It give details of
It hides the
storage and
internal details of
representation of
Data Database
Abstraction data
Integrity
Integrity
Constraints are
constraints are
difficult to
Integrity easy to implement
Constraints implement
To access data in
a file , user
No such attributes
requires attributes
are required.
such as file name,
Attributes file location.
Oracle, SQL
Cobol, C++
Example Server
The main difference between a file system and a DBMS (Database Management System)
is the way they organize and manage data.
1. File systems are used to manage files and directories, and provide basic operations for
creating, deleting, renaming, and accessing files. They typically store data in a hierarchical
structure, where files are organized in directories and subdirectories. File systems are simple
and efficient, but they lack the ability to manage complex data relationships and ensure data
consistency.
2. On the other hand, DBMS is a software system designed to manage large amounts of
structured data, and provide advanced operations for storing, retrieving, and manipulating
data. DBMS provides a centralized and organized way of storing data, which can be
accessed and modified by multiple users or applications. DBMS offers advanced features
like data validation, indexing, transactions, concurrency control, and backup and recovery
mechanisms. DBMS ensures data consistency, accuracy, and integrity by enforcing data
constraints, such as primary keys, foreign keys, and data types.
In summary, file systems are suitable for managing small amounts of unstructured data, while
DBMS is designed for managing large amounts of structured data, and offers more advanced
features for ensuring data integrity, security, and performance.
4 ) Explain DBA roles and
responsibilities
A Database Administrator (DBA) is an individual or person responsible for controlling,
maintaining, coordinating, and operating a database management system. Managing,
securing, and taking care of the database systems is a prime responsibility. They are
responsible and in charge of authorizing access to the database, coordinating,
capacity, planning, installation, and monitoring uses, and acquiring and gathering
software and hardware resources as and when needed. Their role also varies from
configuration, database design, migration, security, troubleshooting, backup, and data
recovery. Database administration is a major and key function in any firm or
organization that is relying on one or more databases. They are overall commanders of
the Database system.
Types of Database Administrator (DBA) :
Administrative DBA –
Their job is to maintain the server and keep it functional. They are concerned with
data backups, security, troubleshooting, replication, migration, etc.
Data Warehouse DBA –
Assigned earlier roles, but held accountable for merging data from various sources
into the data warehouse. They also design the warehouse, with cleaning and scrubs
data prior to loading.
Cloud DBA –
Nowadays companies are preferring to save their workpiece on cloud storage. As it
reduces the chance of data loss and provides an extra layer of data security and
integrity.
Development DBA –
They build and develop queries, stores procedure, etc. that meets firm or
organization needs. They are par at programming.
Application DBA –
They particularly manage all requirements of application components that interact
with the database and accomplish activities such as application installation and
coordination, application upgrades, database cloning, data load process
management, etc.
Architect –
They are held responsible for designing schemas like building tables. They work to
build a structure that meets organizational needs. The design is further used by
developers and development DBAs to design and implement real applications.
OLAP DBA –
They design and build multi-dimensional cubes for determination support or OLAP
systems.
Data Modeler –
In general, a data modeler is in charge of a portion of a data architect’s duties. A data
modeler is typically not regarded as a DBA, but this is not a hard and fast rule.
Task-Oriented DBA –
To concentrate on a specific DBA task, large businesses may hire highly specialised
DBAs. They are quite uncommon outside of big corporations. Recovery and backup
DBA, whose responsibility it is to guarantee that the databases of businesses can be
recovered, is an example of a task-oriented DBA. However, this specialism is not
present in the majority of firms. These task-oriented DBAs will make sure that highly
qualified professionals are working on crucial DBA tasks when it is possible.
Database Analyst –
This position doesn’t actually have a set definition. Junior DBAs may occasionally be
referred to as database analysts. A database analyst occasionally performs functions
that are comparable to those of a database architect. The term “Data Administrator”
is also used to describe database analysts and data analysts. Additionally, some
businesses occasionally refer to database administrators as data analysts.
Importance of Database Administrator (DBA) :
Database Administrator manages and controls three levels of database internal level,
conceptual level, and external level of Database management system architecture
and in discussion with the comprehensive user community, gives a definition of the
world view of the database. It then provides an external view of different users and
applications.
Database Administrator ensures held responsible to maintain integrity and security of
database restricting from unauthorized users. It grants permission to users of the
database and contains a profile of each and every user in the database.
Database Administrators are also held accountable that the database is protected
and secured and that any chance of data loss keeps at a minimum.
Database Administrator is solely responsible for reducing the risk of data loss as it
backup the data at regular intervals.
Role and Duties of Database Administrator (DBA) :
Decides hardware –
They decide on economical hardware, based on cost, performance, and efficiency of
hardware, and best suits the organization. It is hardware that is an interface between
end users and the database.
Manages data integrity and security –
Data integrity needs to be checked and managed accurately as it protects and
restricts data from unauthorized use. DBA eyes on relationships within data to
maintain data integrity.
Database Accessibility –
Database Administrator is solely responsible for giving permission to access data
available in the database. It also makes sure who has the right to change the content.
Database design –
DBA is held responsible and accountable for logical, physical design, external model
design, and integrity and security control.
Database implementation –
DBA implements DBMS and checks database loading at the time of its
implementation.
Query processing performance –
DBA enhances query processing by improving speed, performance, and accuracy.
Tuning Database Performance –
If the user is not able to get data speedily and accurately then it may lose
organization’s business. So by tuning SQL commands DBA can enhance the
performance of the database.
Various responsibilities of Database Administrator (DBA) :
Responsible for designing overall database schema (tables & fields).
To select and install database software and hardware.
Responsible for deciding on access methods and data storage.
DBA selects appropriate DBMS software like oracle, SQL server or MySQL.
Used in designing recovery procedures.
DBA decides the user access level and security checks for accessing, modifying or
manipulating data.
DBA is responsible for specifying various techniques for monitoring the database
performance.
DBA is responsible for operation managements.
The operation management deals with the data problems which arises on day to day
basis, and the responsibilities include are:
1. Investigating if any error is been found in the data.
2. Supervising of restart and recovery procedures in case of any event failure.
3. Supervising reorganization of the databases.
4. Controlling and handling all periodic dumps of data.
Skills Required for DBA:
1. The various programming and soft skills are required to DBA are as follows,
Good communication skills
Excellent knowledge of databases architecture and design and RDBMS.
Knowledge of Structured Query Language (SQL).
2. In addition, this aspect of database administration includes maintenance of data
security, which involves maintaining security authorization tables, conducting periodic
security audits, investigating all known security breaches.
3. To carry out all these functions, it is crucial that the DBA has all the accurate
information about the company’s data readily on hand. For this purpose he maintains a
data dictionary.
4. The data dictionary contains definitions of all data items and structures, the various
schemes, the relevant authorization and validation checks and the different mapping
definitions.
5. It should also have information about the source and destination of a data item and
the flow of a data item as it is used by a system. This type of information is a great help
to the DBA in maintaining centralized control of data.
If the structure of the database or its specifications change at any point of time, it
should be reflected in the data dictionary. This is the responsibility of the database
management system in which the data dictionary resides.
This is not as useful or easy to handle as an active data dictionary. A passive data
dictionary is maintained separately to the database whose contents are stored in
the dictionary. That means that if the database is modified the database dictionary
is not automatically updated as in the case of Active Data Dictionary.
So, the passive data dictionary has to be manually updated to match the database.
This needs careful handling or else the database and data dictionary are out of
sync.
1) Centralized Database
2) Distributed Database
This database is based on the relational data model, which stores data in the form
of rows(tuple) and columns(attributes), and together forms a table(relation). A
relational database uses SQL for storing, manipulating, as well as maintaining the
data. E.F. Codd invented the database in 1970. Each table in the database carries a
key that makes the data unique from others. Examples of Relational databases are
MySQL, Microsoft SQL Server, Oracle, etc.
There are following four commonly known properties of a relational model known as
ACID properties, where:
A means Atomicity: This ensures the data operation will complete either with
success or with failure. It follows the 'all or nothing' strategy. For example, a
transaction will either be committed or will abort.
C means Consistency: If we perform any operation over the data, its value before
and after the operation should be preserved. For example, the account balance
before and after the transaction should be correct, i.e., it should remain conserved.
I means Isolation: There can be concurrent users for accessing data at the same
time from the database. Thus, isolation between the data should remain isolated.
For example, when multiple transactions occur at the same time, one transaction
effects should not be visible to the other transactions in the database.
D means Durability: It ensures that once it completes the operation and commits
the data, data changes should remain permanent.
4) NoSQL Database
Non-SQL/Not Only SQL is a type of database that is used for storing a wide range of
data sets. It is not a relational database as it stores data not only in tabular form but
in several different ways. It came into existence when the demand for building
modern applications increased. Thus, NoSQL presented a wide variety of database
technologies in response to the demands. We can further divide a NoSQL database
into the following four types:
a. Key-value storage: It is the simplest type of database storage where it
stores every single item as a key (or attribute name) holding its value,
together.
b. Document-oriented Database: A type of database used to store data as
JSON-like document. It helps developers in storing data by using the same
document-model format as used in the application code.
c. Graph Databases: It is used for storing vast amounts of data in a graph-like
structure. Most commonly, social networking websites use the graph
database.
d. Wide-column stores: It is similar to the data represented in relational
databases. Here, data is stored in large columns together, instead of storing
in rows.
5) Cloud Database
A type of database where data is stored in a virtual environment and executes over
the cloud computing platform. It provides users with various cloud computing
services (SaaS, PaaS, IaaS, etc.) for accessing the database. There are numerous
cloud platforms, but the best options are:
6) Object-oriented Databases
The type of database that uses the object-based data model approach for storing
data in the database system. The data is represented and stored as objects which
are similar to the objects used in the object-oriented programming language.
7) Hierarchical Databases
It is the type of database that stores data in the form of parent-children relationship
nodes. Here, it organizes data in a tree-like structure.
Data get stored in the form of records that are connected via links. Each child
record in the tree will contain only one parent. On the other hand, each parent
record can have multiple child records.
8) Network Databases
It is the database that typically follows the network data model. Here, the
representation of data is in the form of nodes connected via links between them.
Unlike the hierarchical database, it allows each record to have multiple children and
parent nodes to form a generalized graph structure.
9) Personal Database
Collecting and storing data on the user's system defines a Personal Database. This
database is basically designed for a single user.
The type of database which creates and updates the database in real-time. It is
basically designed for executing and handling the daily data operations in several
businesses. For example, An organization uses operational databases for managing
per day transactions.
Tuple in DBMS
A tuple is an essential component in the relational database management system.
Relational database management stores data in tables.
A tuple contains all the information of a particular entity. The table is composed of
fields and a tuple. A tuple represents a row in the table and the data associated with
the entity. The data in RDBMS is arranged across several columns and rows. The
column represents the attribute of an entity, such as age, gender, marks, etc.
In the DBMS relational model, the database is represented as a collection of
relations between entities and their attributes.
A relation represents a table that contains certain values in the form of rows and
columns, where a row or tuple is a collection of related data values. Each value
stored inside each row, column, and the table is important for determining the
table's name. Though the data is arranged in tables in RDBMS, the data storage
does not depend on the logical structure of the data.
A tuple in the DBMS refers to a single record in the relational db. It represents the
entire data in a single row of the relational table. The data is stored in the table
format by attribute and tuples in DBMS.
The user can perform several operations on the data stored in the field or tuple of
the tables. These operations include inserting, removing, modifying, or update on
the data values stored in the table. The user can also perform a join operation on
the tuples in two different relations. Join operations are used to combine the data
values in two tables.
Below is an example of a tuple with fields such as the client's name, contact
number, email address, and nationality of the client.
The management systems implement the relational model called the relational
database management system. Most of the time, when a user wants to store data in
a DBMS, the data is stored in tables. It is easy to read the data in tables as it is
more organized.
In DBMS, a unique key is assigned to each table that is used to organize and identify
the elements. This key is known as the table's primary key and is unique for each
record present. In DBMS, the user can add a column containing the value from
another table's column. This enables the user to link the tuple of different tables.
The rows in the tables represent the records in the database, and the columns
represent the attributes associated with the entity.
A tuple is a single row in a database. The record contains all the information about
an entity in the relation. A tuple or record is a name associated with using a
particular entity in the item. In contrast, in mathematics, a tuple is an ordered list of
elements that contains a set of associated data to the elements in the table.
Given below is a table that contains several tuples or records. Using this table, we
will learn to work with a tuple in DBMS. The below table is a student record table
that contains information such as students' names, age, subjects, and marks. The
table has an additional column ID that contains a unique value for each row present
in the table.
Thus, as you can see that each row in the database contains information about
another individual.
For instance, the first row contains information about a student named Harsh. This
row can also be referred to as the record, as it contains the record of each student
in the database. These rows and records in the database are called a tuple.
Thus, in the database management system, the tuple is a row containing all the
information related to a particular entity. The entity can be an employee, a student,
a customer, or a user.
In the above figure, you can see that a tuple or record contains the entire
information about a single entity, such as the age, subject, and marks obtained in
the subject.
Most database stores data in the form of a table that consists of tuples and
attributes. A row corresponding data to a certain object is called a tuple in a
database management system
What is a relation ?
A general term used in database design is a “relational database"—but a database
relation is not the same thing and does not imply, as its name suggests, a
relationship between tables. A database relation simply refers to an individual table
in a relational database.
In a relational database, the table is a relation because it stores the relation
between data in its column-row format. The columns are the table's attributes,
while the rows represent the data records. A single row is known as a tuple to
database designers.
its name must be unique in the database, for example - a database cannot
contain multiple tables of the same name.
Each relation must have a set of columns or attributes, and it must have a
set of rows to contain the data. As with the table names, no attributes can
have the same name.
A tuple (or row) can be a duplicate. In practice, a database might actually
contain duplicate rows, but there should be practices in place to avoid this,
such as the use of unique primary keys (next up).
Given that a tuple cannot be a duplicate, it follows that a relation must contain at
least one attribute (or column) that identifies each tuple (or row) uniquely. This is
usually the primary key. This primary key cannot be duplicated.
Further, field must contain a single value. For example - you cannot enter
something like "Tom Smith" and expect the database to understand that you have a
first and last name; rather, the database will understand that the value of that cell
is exactly what has been entered.
1. Primary key
o It is the first key used to identify one and only one instance of an entity
uniquely. An entity can contain multiple keys, as we saw in the
PERSON table. The key which is most suitable from those lists becomes
a primary key.
o In the EMPLOYEE table, ID can be the primary key since it is unique for
each employee. In the EMPLOYEE table, we can even select
License_Number and Passport_Number as primary keys since they are
also unique.
o For each entity, the primary key selection is based on requirements
and developers.
2. Candidate key
o A candidate key is an attribute or set of attributes that can uniquely
identify a tuple.
o Except for the primary key, the remaining attributes are considered a
candidate key. The candidate keys are as strong as the primary key.
For example: In the EMPLOYEE table, id is best suited for the primary key.
The rest of the attributes, like SSN, Passport_Number, License_Number, etc.,
are considered a candidate key.
3. Super Key
Super key is an attribute set that can uniquely identify a tuple. A super key is
a superset of a candidate key.
Keys in DBMS
4. Foreign key
o Foreign keys are the column of the table used to point to the primary
key of another table.
o Every employee works in a specific department in a company, and
employee and department are two different entities. So we can't store
the department's information in the employee table. That's why we link
these two tables through the primary key of one table.
o We add the primary key of the DEPARTMENT table, Department_Id, as
a new attribute in the EMPLOYEE table.
o In the EMPLOYEE table, Department_Id is the foreign key, and both the
tables are related.
5. Alternate key
The key created using arbitrarily assigned data are known as artificial keys.
These keys are created when a primary key is large and complex and has no
relationship with many other relations. The data values of the artificial keys
are usually numbered in a serial order. For example, the primary key, which
is composed of Emp_ID, Emp_role, and Proj_ID, is large in employee
relations. So it would be better to add a new virtual attribute to identify each
tuple in the relation uniquely.
Constraints on Relational
Database Model
01 Bikash 6000000009
02 Paul 9000090009
01 Tuhin 9234567892
Explanation: In the above table, EID is the primary key, and the
first and the last tuple have the same value in EID ie 01, so it is
violating the key constraint.
3. Entity Integrity Constraints
Entity Integrity constraints say that no primary key can take a
NULL value, since using the primary key we identify each tuple
uniquely in a relation.
Example:
EID Name Phone
01 Bikash 9000900099
02 Paul 600000009
01 Divine 12
02 Dino 22
EID Name DNO
04 Vivian 14
DNO Place
12 Jaipur
13 Mumbai
14 Delhi
There are three basic operations that can change the states of
relations in the data-base: Insert, Delete,and Update (or
Modify).
Insert
Delete
Update
(or Modify) is used to change the values of some attributes in existing tuples.
Whenever these operations are applied, the integrity constraints specified on the
relational database schema shouldnot be violated.
The Insert operation provides a list of attribute values for a new tuple that is to be
inserted into a relation R.
Domain constraints
can be violated if an attribute value is given that does not appear in the
correspondingdomain or is not of the appropriate data type.
Key constraints
can be violated if a key value in the new tuple t already exists in another tuple in
the relationr(R).
Entity integrity
can be violated if any part of the primary key of the new tuple t is NULL.
Referential integrity
can be violated if the value of any foreign key in t refers to a tuple that does not
exist in thereferenced relation. Here are some examples to illustrate this
discussion.
the default option is to reject the insertion. In this case, it would be useful if the
DBMS could provide areason to the user as to why the insertion was rejected.
Another option is to attempt to correct the reason for rejecting the insertion, but
this is typically not usedfor violations caused by Insert
The Delete Operation
The DELETE statement is used to delete rows from a table. Generally, DELETE
statement removes one or morerecords form a table.
This occurs if the tuple being deleted is referenced by foreign keys from
other tuples in the database.
•
To specify deletion, a condition on the attributes of the relation selects the
tuple (or tuples) to be deleted.
Here are some examples :1)Operation: Delete the WORKS_ON tuple with Essn=
‘999887777’ and Pno= 10. This deletion is acceptable and deletes exactly one tuple.
This deletion is not acceptable, because there are tuples in WORKS_ON that refer
to this tuple.
This deletion will result in even worse referential integrity violations, because the
tuple involved is referenced bytuples from the
relations.
The Delete Operation:
Rejectt
he deletion.2)
Cascade
, is to modify the referencing attribute values that cause the violation; each such
value iseither set to NULL or changed to reference another default valid tuple.
Notice that if a referencing attribute thatcauses a violation is part of the primary key,
it cannot be set to NULL; otherwise, it would violate entity integrity.4)Combinations of
these three options are also possible.
The Update (or Modify) operation is used to change the values of one or more
attributes in a tuple (or tuples) of some relation R. It is necessary to specify a
condition on the attributes of the relation to select the tuple (or tuples) to be
modified.Here are some examples1) Update the salary of the EMPLOYEE tuple with
Ssn= ‘999887777’ to 28000. Acceptable.2) Update the Dno of the EMPLOYEE tuple with
Ssn= ‘999887777’ to 1.Acceptable.3) Update the Dno of the EMPLOYEE tuple with Ssn=
‘999887777’ to 7. Unacceptable, because it violates referential integrity.4) Update
the Ssn of the EMPLOYEE tuple with Ssn= ‘999887777’ to‘987654321’.Unacceptable,
because it violates primary key constraint by repeating a value that already exists
as a primary key in another tuple;it violates referential integrity constraints
because there are other relations that refer to the existing value of Ssn
Updating an attribute that is neither part of a primary key nor of a foreign key
usually causes no problems; the DBMSneed only check to confirm that the new
value is of the correct data type and domain. Modifying a primary key value
issimilar to deleting one tuple and inserting another in its place because we use
the primary key to identify tuples.
What is an ER Model?
ER Diagram helps you conceptualize the database and lets you know
which fields need to be embedded for a particular entity
ER Diagram gives a better understanding of the information to be stored
in a database
It reduces complexity and allows database designers to build databases
quickly
It helps to describe elements using Entity-Relationship models
It allows users to get a preview of the logical structure of the database
Entities
Weak Entity
Attributes
Key Attribute
Composite Attribute
Multivalued Attribute
Derived Attribute
Relationships
One-to-One Relationships
One-to-Many Relationships
Many-to-One Relationships
Many-to-Many Relationships
Entities
Weak Entity
An entity that makes reliance over another entity is called a weak entity
You showcase the weak entity as a double rectangle in ER Diagram.
In the example below, school is a strong entity because it has a primary
key attribute - school number. Unlike school, the classroom is a weak entity
because it does not have any primary key and the room number here acts
only as a discriminator.
Attribute
Key Attribute
Key attribute uniquely identifies an entity from an entity set.
It underlines the text of a key attribute.
For example: For a student entity, the roll number can uniquely identify a
student from a set of students.
Composite Attribute
An attribute that is composed of several other attributes is known as a
composite attribute.
An oval showcases the composite attribute, and the composite attribute
oval is further connected with other ovals.
Multivalued Attribute
Some attributes can possess over one value, those attributes are called
multivalued attributes.
The double oval shape is used to represent a multivalued attribute.
Derived Attribute
An attribute that can be derived from other attributes of the entity is known
as a derived attribute.
In the ER diagram, the dashed oval represents the derived attribute.
Relationship
One-to-Many Relationship
When a single element of an entity is associated with more than one
element of another entity, it is called a one-to-many relationship
For example, a customer can place many orders, but an order cannot be
placed by many customers.
Many-to-One Relationship
When more than one element of an entity is related to a single element of
another entity, then it is called a many-to-one relationship.
For example, students have to opt for a single course, but a course can
have many students.
Many-to-Many Relationship
When more than one element of an entity is associated with more than one
element of another entity, this is called a many-to-many relationship.
For example, you can assign an employee to many projects and a project
can have many employees.
First, identify all the Entities. Embed all the entities in a rectangle and
label them properly.
Identify relationships between entities and connect them using a diamond
in the middle, illustrating the relationship. Do not connect relationships
with each other.
Connect attributes for entities and label them properly.
Eradicate any redundant entities or relationships.
Make sure your ER Diagram supports all the data provided to design the
database.
Effectively use colors to highlight key areas in your diagrams.
Conclusion
It should convert to :
Persons( personid , name, lastname, email )
House ( houseid , num , address, personid)
5. N:N Relationships
We normally use tables to express such type of
relationship. This is the same for N − ary relationship of
ER diagrams. For instance, The Person can live or work in
many countries. Also, a country can have many people.
To express this relationship within a relational schema we
use a separate table as shown below:
1. Internal Level
o The internal level has an internal schema which describes
the physical storage structure of the database.
o The internal schema is also known as a physical schema.
o It uses the physical data model. It is used to define that how
the data will be stored in a block.
o The physical level is used to describe complex low-level data
structures in detail.
o This level is also known as physical level. This level describes how
the data is actually stored in the storage devices. This level is also
responsible for allocating space to the data. This is the lowest level of
the architecture.
o
2. Conceptual Level
o The conceptual schema describes the design of a database
at the conceptual level. Conceptual level is also known as
logical level.
o The conceptual schema describes the structure of the whole
database.
o The conceptual level describes what data are to be stored in
the database and also describes what relationship exists
among those data.
o In the conceptual level, internal details such as an
implementation of the data structure are hidden.
o Programmers and database administrators work at this level.
o It is also called logical level. The whole design of the database such
as relationship among data, schema of data etc. are described in this
level.
o Database constraints and security are also implemented in this level
of architecture. This level is maintained by DBA (database
administrator).
o
3. External Level
Database Manager
It is the interface between low-level data, application programs and queries. A
database manager is a program module responsible for interfacing with the
database file system to the user queries. It enforces constraints to maintain the
consistency and integrity of the data as well as its security. It synchronizes the
simultaneous operations performed by concurrent users. It also performs backup
and recovery operations.
Interaction with File Manager - The raw data is stored on the disk using
the file system which is usually provided by a conventional operating system.
The database manager translates the various DML statements into low-level
file system commands. Thus, the database manager is responsible for the
actual storing, retrieving and updating of data in the database.
Integrity Enforcement - The data values stored in the database must
satisfy certain types of consistency constraints. These constraints must be
specified explicitly by the DBA. If such constraints are specified, then the
database manager can check whether updates to the database result in the
violation of any of these constraints and if so appropriate action may be
imposed.
Security Enforcement - Not every user of the database needs to have
access to the entire content of the database. It is the job of the database
manager to enforce these security requirements.
Backup and Recovery - It is the responsibility of database manager to
detect system failures due to disk crash, power failure, software errors, etc
and restore the database to a state that existed prior to the occurrence of the
failure. This is usually accomplished through the backup and recovery
procedures.
Concurrency Control - When several users update the database
concurrently, the consistency of data may no longer be preserved. It is
necessary for the system to control the interaction among the concurrent
users, and achieving such a control is one of the responsibilities of database
manager.
Query Processor:
The query language processor is responsible for receiving query language
statements and changing them from the English like syntax of the query language
to a form the DBMS can understand.
It consists of two separate parts:
The parser
The query optimizer
The query optimizer examines the query language statements, and tries to
choose the best and most efficient way of executing the query. To do this, the query
optimizer will generate several query plans in which operations are performed in
different orders, and then try to estimate which plan will execute most efficiently.
When making this estimate, the query optimizer may examine factors such as: CPU
time, disk time, network time, sorting methods, and scanning methods.
UNIT – 2
Part 1 – pdf sent
UNIT 2 - Part 2
Physical database design issue :
Storage of database on hard disks :
Suppose we have four records R1, R3 and so on upto R9 and R8 in a sequence. Hence, records are
nothing but a row in the table. Suppose we want to insert a new record R2 in the sequence, then it will
be placed at the end of the file. Here, records are nothing but a row in any table.
2. Sorted File Method:
o In this method, the new record is always inserted at the file's end, and then it will sort the
sequence in ascending or descending order. Sorting of records is based on any primary key or
any other key.
o In the case of modification of any record, it will update the record and then sort the file, and
lastly, the updated record is placed in the right place.
Suppose there is a preexisting sorted sequence of four records R1, R3 and so on upto R6 and R7.
Suppose a new record R2 has to be inserted in the sequence, then it will be inserted at the end of the
file, and then it will sort the sequence.
If we want to search, update or delete the data in heap file organization, then we need to traverse the
data from staring of the file till we get the requested record.
If the database is very large then searching, updating or deleting of record will be time-consuming
because there is no sorting or ordering of records. In the heap file organization, we need to check all
the data until we get the requested record.
When a record has to be received using the hash key columns, then the address is generated, and the
whole record is retrieved using that address. In the same way, when a new record has to be inserted,
then the address is generated using the hash key and record is directly inserted. The same process is
applied in the case of delete and update.
In this method, there is no effort for searching and sorting the entire file. In this method, each record
will be stored randomly in the memory.
B+ File Organization
o B+ tree file organization is the advanced method of an indexed sequential access method. It
uses a tree-like structure to store records in File.
o It uses the same concept of key-index where the primary key is used to sort the records. For
each primary key, the value of the index is generated and mapped with the record.
o The B+ tree is similar to a binary search tree (BST), but it can have more than two children. In
this method, all the records are stored only at the leaf node. Intermediate nodes act as a
pointer to the leaf nodes. They do not contain any records.
The above B+ tree shows that:
o There is one root node of the tree, i.e., 25.
o There is an intermediary layer with nodes. They do not store the actual record. They have only
pointers to the leaf node.
o The nodes to the left of the root node contain the prior value of the root and nodes to the right
contain next value of the root, i.e., 15 and 30 respectively.
o There is only one leaf node which has only values, i.e., 10, 12, 17, 20, 24, 27 and 29.
o Searching for any record is easier as all the leaf nodes are balanced.
o In this method, searching any record can be traversed through the single path and accessed
easily.
If any record has to be retrieved based on its index value, then the address of the data block is fetched
and the record is retrieved from the memory.
Pros of ISAM:
o In this method, each record has the address of its data block, searching a record in a huge
database is quick and easy.
o This method supports range retrieval and partial retrieval of records. Since the index is based
on the primary key values, we can retrieve the data for the given range of value. In the same
way, the partial value can also be easily searched, i.e., the student name starting with 'JA' can
be easily searched.
Cons of ISAM
o This method requires extra space in the disk to store the index value.
o When the new records are inserted, then these files have to be reconstructed to maintain the
sequence.
o When the record is deleted, then the space used by it needs to be released. Otherwise, the
performance of the database will slow down.
Cluster file organization
o When the two or more records are stored in the same file, it is known as clusters. These files
will have two or more tables in the same data block, and key attributes which are used to map
these tables together are stored only once.
o This method reduces the cost of searching for various records in different files.
o The cluster file organization is used when there is a frequent need for joining the tables with
the same condition. These joins will give only a few records from both tables. In the given
example, we are retrieving the record for only particular departments. This method can't be
used to retrieve the record for the entire department.
In this method, we can directly insert, update or delete any record. Data is sorted based on the key
with which searching is done. Cluster key is a type of key with which joining of the table is performed.
Types of Cluster file organization:
Cluster file organization is of two types:
1. Indexed Clusters:
In indexed cluster, records are grouped based on the cluster key and stored together. The above
EMPLOYEE and DEPARTMENT relationship is an example of an indexed cluster. Here, all the records are
grouped based on the cluster key- DEP_ID and all the records are grouped.
2. Hash Clusters:
It is similar to the indexed cluster. In hash cluster, instead of storing the records based on the cluster
key, we generate the value of the hash key for the cluster key and store the records with the same
hash key value.
2. In the library, the books are arranged on the shelf in an alphabetical order. If
you are looking for a book starting with the the letter ‘A’ then you go to the shelf ‘A’.
Here shelf naming with the letter ‘A’ is the index. Imagine if the books are not arranged
in alphabetical order in shelves, it would take a very long time to search for a book.
1. First field is the search key, this is the column that a user can use to access the
record quickly. For example, if a user is searching for a student in database, the user
can use student id as a search key to quickly locate the student record.
2. The second field contains the address of the student record in the database.
Remember indexing doesn’t replicate the whole database, rather it creates an index that
refers to the actual data in database. This field is a reference to the data. If user is
searching for a student with student id “S01” then the S01 is the search key and the
second field of the index contains the address where the student data such as student
name, age, address is stored.
Indexing Methods
Ordered indices
The indices are usually sorted to make searching
faster. The indices which are sorted are known as
ordered indices.
Example: Suppose we have an employee table
with thousands of record and each of which is 10
bytes long. If their IDs start with 1, 2, 3....and so on
and we have to search student with ID-543.
o In the case of a database with no index, we
have to search the disk block from starting till
it reaches 543. The DBMS will read the record
after reading 543*10=5430 bytes.
o In the case of an index, we will search using
indexes and the DBMS will read the record
after reading 542*2= 1084 bytes which are
very less compared to the previous case.
Primary Index
o If the index is created on the basis of the
1. Dense Index
In Dense Index, there is an index for every record in the database. For example, if a table
student contains 100 records then in dense index the number of indices would be 100, one
index for each record in table.
If more than one record has the same search key then the dense index points to the first record
in the database that has the search key.
The dense name is given to this index is based on the fact that every record in the database has
a corresponding index in index file so the index file is very dense in this index based database.
Advantages of dense indexes:
1. Searching a record is faster compared to other indexes.
2. It doesn’t require the database to be sorted in any order to generate a dense indexes.
2. Sparse Index
In this index based system, the indexes of very few data items are maintained in the index
file. Unlike Dense index system where every record has an index entry in index file, in this
system, indexes are limited to one per block of data items as shown in the following diagram.
In sparse indexing database needs to be sorted in an order.
For example, let’s say we are creating a sparse index file for student database that contains
records for 100 students.
Student records are divided in blocks where every block contains two records. If index file
contains the indexes for alternate records then we need to maintain indexes for only 50 records
whereas in dense index system, we had to have 100 records in index file.
be generated.
It requires the
sorted.
3. Clustered Index
As the name suggests, in clustered index, the records with the similar type are grouped together
to form a cluster and an index is created for this cluster which is maintained in clustered index
file.
For example:
Let’s say students are assigned to multiple courses and we are creating indexes
on course_id filed. In this case, all the students that are assigned to a
particular course_id form a cluster and the index for that particular course_id points to this
cluster as shown in the following diagram.
This helps in quickly locating a record in a particular cluster as the the size of the cluster is
limited and smaller than the actual database so searching a record is faster.
One of the type of clustered indexing is primary indexing: In this type of clustered indexing, data
is sorted based on the search key. In this type of indexing, searching is even faster as the
records are sorted.
For example, let’s say we have records of 300 students in database, instead of creating indexes
for 300 records on the root level, we create indexes for 1st student records, 101st student and
201st student. This index is maintained in the primary memory such as RAM. Here we have
divided the complete index file in three groups.
The second level of indexes are stored in hard disk, the primary index file is stored in
RAM, refers to this file and this file then points to the actual data block in memory as shown
below:
5. Multilevel index
B+ Tree
o The B+ tree is a balanced binary search tree. It
follows a multi-level index format.
o In the B+ tree, leaf nodes denote actual data
pointers. B+ tree ensures that all leaf nodes remain
at the same height.
o In the B+ tree, the leaf nodes are linked using a link
list. Therefore, a B+ tree can support random access
as well as sequential access.
Structure of B+ Tree
o In the B+ tree, every leaf node is at equal distance
from the root node. The B+ tree is of the order n
where n is fixed for every B+ tree.
o It contains an internal node and leaf node.
Internal node
o An internal node of the B+ tree can contain at least
n/2 record pointers except the root node.
o At most, an internal node of the tree contains n
pointers.
Leaf node
o The leaf node of the B+ tree can contain at least n/2
record pointers and n/2 key values.
o At most, a leaf node contains n record pointer and n
key values.
o Every leaf node of the B+ tree contains one block
pointer P to point to next leaf node.
Searching a record in B+ Tree
B+ Tree Insertion