DBMS Ca3
DBMS Ca3
DBMS Ca3
Second normal form (2NF): This requires that all non-key attributes in a table are
fully dependent on the primary key, meaning that there should be no partial
dependencies.
Third normal form (3NF): This requires that all non-key attributes in a table are
dependent only on the primary key, and not on any other non-key attributes.
There are additional normal forms beyond 3NF, such as Boyce-Codd normal form
(BCNF) and fourth normal form (4NF), which further refine the rules for table
structure and dependency.
Normalization is an important concept in database design because it helps to ensure
data integrity and consistency, and can make it easier to query and analyze data.
However, it is important to balance the benefits of normalization with the practical
considerations of database performance and complexity.
Yes, there are a set of rules in normalization that are used to ensure that a database
is organized in a way that reduces data redundancy and improves data integrity. The
most commonly used rules for normalization are based on normal forms, which are a
set of guidelines for structuring tables in a database.
The most commonly used normal forms and their associated rules are:
First Normal Form (1NF): This requires that each table has a primary key, and
that each attribute in the table is atomic, meaning it cannot be divided into
smaller pieces.
Second Normal Form (2NF): This requires that all non-key attributes in a table
are fully dependent on the primary key, meaning that there should be no partial
dependencies.
Third Normal Form (3NF): This requires that all non-key attributes in a table are
dependent only on the primary key, and not on any other non-key attributes.
There are also additional normal forms beyond 3NF, such as Boyce-Codd Normal
Form (BCNF) and Fourth Normal Form (4NF), which further refine the rules for table
structure and dependency.
In general, the rules for normalization are designed to ensure that a database is
organized in a way that minimizes data redundancy and inconsistencies, and makes
it easier to query and analyze the data. By following these rules, a database can be
optimized for performance, scalability, and maintainability.
Database Design:
Database design can be generally defined as a collection of tasks or processes that enhance the
designing, development, implementation, and maintenance of enterprise data management
system. Designing a proper database reduces the maintenance cost thereby improving data
consistency and the cost-effective measures are greatly influenced in terms of disk storage space.
Therefore, there has to be a brilliant concept of designing a database. The designer should follow
the constraints and decide how the elements correlate and what kind of data must be stored.
The main objectives behind database designing are to produce physical and logical design models
of the proposed database system. To elaborate this, the logical model is primarily concentrated on
the requirements of data and the considerations must be made in terms of monolithic
considerations and hence the stored physical data must be stored independent of the physical
conditions. On the other hand, the physical database design model includes a translation of the
logical design model of the database by keep control of physical media using hardware resources
and software systems such as Database Management System (DBMS).
Insertion Anomaly: This occurs when a user tries to insert new data into a table,
but cannot do so because the required data for other attributes in the table is
missing. This can happen when a table is not properly normalized, and attributes
are stored redundantly.
Deletion Anomaly: This occurs when deleting a record from a table accidentally
deletes other important data that is still required by other records in the same
table. This can happen when a table is not properly normalized, and the same
data is stored in multiple places.
Update Anomaly: This occurs when a user tries to update some data in a table,
but the update affects multiple records unintentionally. This can happen when a
table is not properly normalized, and the same data is stored in multiple places.
These anomalies can lead to inconsistent or incomplete data, which can cause
problems such as inaccurate reports, lost data, and difficulty in querying or analyzing
the data. To avoid these anomalies, it is important to properly normalize the tables
in a database, eliminate data redundancies, and ensure that data is stored in a way
that supports efficient data retrieval and maintenance.
Yes, there are ways to solve the anomalies that may arise in database design. The
most effective way to eliminate anomalies is to normalize the database tables
properly. Normalization is the process of breaking down a large table into smaller,
more manageable tables, each containing only related data. This process eliminates
data redundancies and ensures that each table contains data related to a single
subject.
By normalizing the tables, the insertion, deletion, and update anomalies can be
minimized or eliminated, as each table will contain only the necessary data and will
be independent of other tables. Additionally, normalization makes it easier to
retrieve and manipulate data from the database, improving data integrity,
consistency, and accuracy.
Another way to solve anomalies is to use database constraints such as primary keys,
foreign keys, and unique constraints, to ensure that the data entered into the tables
meets certain requirements. Constraints can help prevent the entry of inconsistent
or incomplete data, and ensure that related data is maintained properly across the
tables.
Overall, the key to solving anomalies in database design is to properly structure the
database tables, eliminate redundancies, and ensure that the data is stored in a way
that supports efficient data retrieval and maintenance.
Consistency: This property ensures that a transaction brings the database from
one valid state to another. All data written to the database must be valid
according to predefined rules and constraints. If any part of a transaction
violates any constraints or rules, the entire transaction is rolled back to maintain
consistency.
Isolation: This property ensures that each transaction is isolated from other
transactions that may be running concurrently. This prevents interference and
ensures that each transaction operates on consistent data. Transactions must be
executed independently without affecting other transactions.
In the context of entity-relationship (ER) modeling, there are two types of entities:
strong entities and weak entities.
A strong entity is an entity that can be uniquely identified by its own attributes,
without relying on the existence of another entity. For example, in a database for a
university, a student entity is a strong entity because it can be uniquely identified by
its student ID number or some other attributes like name or date of birth. Strong
entities have their own primary keys that uniquely identify each record in the table.
On the other hand, a weak entity is an entity that cannot be uniquely identified by its
own attributes alone. It relies on the existence of another entity, called its owner
entity, to give it meaning and context. A weak entity always has a partial key, which
is a set of attributes that, combined with the primary key of its owner entity, can
uniquely identify each record in the table. For example, in a database for a hospital,
a ward entity may be a weak entity because it cannot be uniquely identified by its
name alone, but requires the existence of a hospital entity to provide context. The
ward entity's partial key could be its ward number, combined with the hospital's
primary key.
In summary, strong entities can stand alone and have their own primary keys, while
weak entities require the existence of an owner entity and have a partial key.
Understanding the difference between strong and weak entities is important in
designing database schemas that accurately capture the relationships and
dependencies between entities in the real-world domain being modeled.
https://www.tutorialandexample.com/er-diagram-for-student-management-system-
in-dbms
Identify the entities: Start by identifying the main entities in the system. In this
case, some of the entities could be Student, Course, Faculty, Department, and
Enrollment.
Identify the relationships: Once you have identified the entities, you need to
identify the relationships between them. For example, a student can enroll in
multiple courses, and a course can have multiple students. Similarly, a faculty
member can teach multiple courses, and a course can have multiple faculty
members.
Define the attributes: Next, you need to define the attributes for each entity. For
example, the Student entity could have attributes such as student ID, name,
date of birth, gender, and contact information. The Course entity could have
attributes such as course ID, course name, course description, and credits.
Draw the E-R diagram: Using the identified entities, relationships, and attributes,
you can now draw the E-R diagram. \
https://www.tutorialandexample.com/er-diagram-for-banking-system-in-dbms
To establish these relationships, tables use primary and foreign keys. A primary key is
a unique identifier for each record in a table, while a foreign key is a key that refers
to the primary key of another table to establish a link between them.
Overall, relationships play a crucial role in designing and managing databases, and
understanding the different types of relationships is essential for effective data
management and querying in DBMS.
DDL stands for Data Definition Language. It is a subset of SQL (Structured Query
Language) used for defining the database schema and creating and modifying
database objects such as tables, indexes, and constraints.
DDL commands are used to create, modify, and delete database objects. Some
common DDL commands include:
CREATE: Used to create a new database object such as a table, index, or view.
ALTER: Used to modify an existing database object.
DROP: Used to delete a database object such as a table, index, or view.
TRUNCATE: Used to remove all data from a table while preserving the table
structure.
RENAME: Used to rename a database object.
DDL commands are used to define the structure and constraints of the database
schema. The schema defines the organization of the data and how the data is stored
in the database. DDL commands are typically executed by database administrators
or developers who have the necessary privileges to modify the database schema.
DCL stands for Data Control Language. It is a subset of SQL (Structured Query
Language) used to manage user access to the database. DCL commands are used to
grant or revoke privileges to users and roles, and to control the level of access users
have to specific database objects.
Some common DCL commands include:
DCL commands are typically executed by database administrators who have the
necessary privileges to manage user access to the database. By controlling user
access, DCL helps to ensure the security and integrity of the data stored in the
database.
DML stands for Data Manipulation Language. It is a subset of SQL (Structured Query
Language) used to manage data stored in a database. DML commands are used to
insert, update, delete, and retrieve data from database tables.
Some common DML commands include:
DML commands are typically executed by users and applications that interact with
the database. They are used to perform various operations on the data stored in the
database, such as retrieving information for reports, updating customer records, or
deleting outdated data.
DML commands are critical to the functioning of database applications and are an
essential component of SQL. They allow users and applications to interact with the
database and manage the data stored within it.
TCL stands for Transaction Control Language. It is a subset of SQL (Structured Query
Language) used to manage transactions in a database. TCL commands are used to
control the changes made to the database by transactions and ensure the integrity
and consistency of data.
Some common TCL commands include:
COMMIT: Used to permanently save the changes made to the database by a
transaction.
ROLLBACK: Used to undo the changes made by a transaction and restore the
database to its previous state.
SAVEPOINT: Used to create a point in the transaction where changes can be
rolled back to if needed.
SET TRANSACTION: Used to specify characteristics of the transaction, such as its
isolation level.
TCL commands are typically used by database administrators and developers to
manage transactions and ensure data consistency. They are used to enforce business
rules and ensure that data is accurate and reliable. TCL commands are an essential
component of SQL and are critical to the functioning of database applications.
What is SQL?
Data Definition Language (DDL): This subset of SQL is used to define and manage
the structure of a database. It includes commands such as CREATE, ALTER, and
DROP.
Data Manipulation Language (DML): This subset of SQL is used to retrieve, insert,
update, and delete data from a database. It includes commands such as SELECT,
INSERT, UPDATE, and DELETE.
Data Control Language (DCL): This subset of SQL is used to control access to a
database. It includes commands such as GRANT and REVOKE.
Data Query Language (DQL): This subset of SQL is used to retrieve data from a
database. It includes the SELECT command, which is used to retrieve data from
one or more tables in a database.
what is savepoint?
Deadlock in DBMS
A deadlock is a condition where two or more transactions are waiting indefinitely for one another
to give up locks. Deadlock is said to be one of the most feared complications in DBMS as no task
ever gets finished and is in waiting state forever.
For example: In the student table, transaction T1 holds a lock on some rows and needs to update
some rows in the grade table. Simultaneously, transaction T2 holds locks on some rows in the
grade table and needs to update the rows in the Student table held by Transaction T1.
Now, the main problem arises. Now Transaction T1 is waiting for T2 to release its lock and similarly,
transaction T2 is waiting for T1 to release its lock. All activities come to a halt state and remain at a
standstill. It will remain in a standstill until the DBMS detects the deadlock and aborts one of the
transactions.
Deadlock Avoidance
o When a database is stuck in a deadlock state, then it is better to avoid the database rather
than aborting or restating the database. This is a waste of time and resource.
o Deadlock avoidance mechanism is used to detect any deadlock situation in advance. A
method like "wait for graph" is used for detecting the deadlock situation but this method
is suitable only for the smaller database. For the larger database, deadlock prevention
method can be used.
Deadlock Detection
In a database, when a transaction waits indefinitely to obtain a lock, then the DBMS should detect
whether the transaction is involved in a deadlock or not. The lock manager maintains a Wait for the
graph to detect the deadlock cycle in the database.
o This is the suitable method for deadlock detection. In this method, a graph is created
based on the transaction and their lock. If the created graph has a cycle or closed loop,
then there is a deadlock.
o The wait for the graph is maintained by the system for every transaction which is waiting
for some data held by the others. The system keeps checking the graph if there is any
cycle in the graph.
AD
The wait for a graph for the above scenario is shown below:
Deadlock Prevention
o Deadlock prevention method is suitable for a large database. If the resources are allocated
in such a way that deadlock never occurs, then the deadlock can be prevented.
o The Database management system analyzes the operations of the transaction whether
they can create a deadlock situation or not. If they do, then the DBMS never allowed that
transaction to be executed.
Wait-Die scheme
In this scheme, if a transaction requests for a resource which is already held with a conflicting lock
by another transaction then the DBMS simply checks the timestamp of both transactions. It allows
the older transaction to wait until the resource is available for execution.
Let's assume there are two transactions Ti and Tj and let TS(T) is a timestamp of any transaction T.
If T2 holds a lock by some other transaction and T1 is requesting for resources held by T2 then the
following actions are performed by DBMS:
1. Check if TS(Ti) < TS(Tj) - If Ti is the older transaction and Tj has held some resource, then
Ti is allowed to wait until the data-item is available for execution. That means if the older
transaction is waiting for a resource which is locked by the younger transaction, then the
older transaction is allowed to wait for resource until it is available.
2. Check if TS(Ti) < TS(Tj) - If Ti is older transaction and has held some resource and if Tj is
waiting for it, then Tj is killed and restarted later with the random delay but with the same
timestamp.
o In wound wait scheme, if the older transaction requests for a resource which is held by the
younger transaction, then older transaction forces younger one to kill the transaction and
release the resource. After the minute delay, the younger transaction is restarted but with
the same timestamp.
o If the older transaction has held a resource which is requested by the Younger transaction,
then the younger transaction is asked to wait until older releases it.
The main differences between DBMS and RDBMS are given below:
No DBMS RDBMS
.
2) In DBMS, data is generally stored in either a In RDBMS, the tables have an identifier called primary key and
hierarchical form or a navigational form. the data values are stored in the form of tables.
4) DBMS does not apply any security with RDBMS defines the integrity constraint for the purpose of ACID
regards to data manipulation. (Atomocity, Consistency, Isolation and Durability) property.
5) DBMS uses file system to store data, so in RDBMS, data values are stored in the form of tables, so
there will be no relation between the a relationship between these data values will be stored in the
tables. form of a table as well.
6) DBMS has to provide some uniform RDBMS system supports a tabular structure of the data and a
methods to access the stored information. relationship between them to access the stored information.
8) DBMS is meant to be for small organization RDBMS is designed to handle large amount of data. it
and deal with small data. it supports multiple users.
supports single user.