DBMS Ca3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

 can you please tell me more about the 'Update anomaly' in DBMS?

In database management systems (DBMS), an update anomaly occurs when data


redundancy leads to inconsistencies or errors in the database. An update anomaly
happens when a change in data is made in one location of a database, but the same
change is not made in all other locations where that data is stored, causing data
inconsistency.
For example, consider a database table that stores information about employees,
including their name, department, and salary. If the department is stored along with
the employee information, then any change in the department name has to be made
in all rows that have that department name, which leads to redundancy. If the
department name is changed in one row but not in others, this can cause an update
anomaly where the department information is inconsistent across the database.
Similarly, if the salary of an employee is stored in multiple tables, and one table is
updated but the other is not, then the salary information would be inconsistent
across the database.
Update anomalies can lead to incorrect or inconsistent data in a database, which can
result in errors or make it difficult to query or analyze the data. To avoid update
anomalies, database designers use techniques such as normalization, which involves
dividing a database into smaller, more manageable tables and eliminating redundant
data.

 Please Define Normalisation in DBMS

Normalization is a process in database design that involves organizing tables and


their attributes to reduce data redundancy and improve data integrity. The main goal
of normalization is to eliminate data anomalies and inconsistencies that can arise
from storing data redundantly in multiple locations within a database.
Normalization involves dividing a database into two or more tables based on the
logical relationships between the data. The process of normalization is typically
divided into multiple normal forms, each of which defines a set of rules for
structuring the tables in a database.
The most commonly used normal forms 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 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.

 Are there any set of rules in NOrmalisation? WHat are they?

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.

 What are the objectives of Normalisation?

The main objectives of normalization in database design are:

 Reducing Data Redundancy: Normalization helps to eliminate duplicate data in a


database, which reduces the storage requirements and improves the accuracy
and consistency of the data.
 Improving Data Integrity: Normalization helps to ensure that the data in a
database is accurate and consistent, by eliminating anomalies such as update,
insert and delete anomalies.

 Simplifying Data Management: Normalization makes it easier to manage and


maintain a database by breaking down complex tables into smaller, more
manageable ones.

 Improving Query Performance: Normalization can improve query performance


by reducing the number of tables that need to be searched, and by eliminating
unnecessary joins.

 Supporting Future Changes: Normalization helps to ensure that a database can


be easily modified and adapted to meet changing business requirements.

Overall, the objectives of normalization are to create a well-structured, efficient, and


easily maintainable database that meets the needs of the users and the business.

 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).

 Describe anomalies present in Database Design.


 In database design, anomalies refer to the inconsistencies, errors, and other
problems that can arise when data is not organized properly. The most common
anomalies are:

 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.

 Is there any way to solve these anolamies?

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.

 Define ACID property.

ACID stands for Atomicity, Consistency, Isolation, and Durability. It is a set of


properties that ensure that database transactions are processed reliably and
accurately.

 Atomicity: This property ensures that a transaction is treated as a single,


indivisible unit of work, either all of the changes in the transaction occur or none
of them occur. If a transaction fails for any reason, all changes made during the
transaction are rolled back, ensuring that the database remains in a consistent
state.

 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.

 Durability: This property ensures that once a transaction is committed, the


changes made to the database are permanent and will survive subsequent
failures or system crashes. Once the transaction is complete, the data should
remain consistent and intact, and any changes should be persistent.

In summary, ACID properties guarantee that transactions are processed accurately


and reliably, ensuring the integrity of the database and the consistency of the data.

 What are Entities?

In the context of database design, an entity is a thing, person, place, concept or


event that can be identified and represented in the database. It can be a physical
object like a product or a person, or a conceptual object like a purchase or a
reservation.
For example, in a database for a library, entities could include books, customers,
borrowing transactions, and authors. Each entity has its own attributes that describe
its properties or characteristics. For instance, attributes of a book entity could
include its title, author, publisher, ISBN, and publication year.
Entities and their attributes are typically represented in an entity-relationship (ER)
diagram, which shows the relationships between entities and how they are
connected. By identifying and representing entities, the database designer can
create a model of the real-world domain being modeled and design a database
schema that accurately captures the relevant information.

 What are Strong and Weak entities?

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.

 Steps to Draw an ER Diagram of Student Management System.

https://www.tutorialandexample.com/er-diagram-for-student-management-system-
in-dbms

Sure, I can provide some guidance on creating an entity-relationship (E-R) diagram


for a student management system in DBMS. Here are the steps you can follow:

 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. \

 ER Diagram of Bank Management System.

https://www.tutorialandexample.com/er-diagram-for-banking-system-in-dbms

 Describe Attribute in DBMS.

In database management systems (DBMS), an attribute is a characteristic or property


of an entity or a relation. It is a named column of a table that contains a specific type
of data or value.
For example, if we have a table named "Employee" in a database, it may have
attributes such as "Employee ID", "Name", "Age", "Gender", "Salary", and
"Department". Each of these attributes has a specific data type, such as integer,
string, or date.
Attributes are used to define the structure of a table and store data in a systematic
and organized manner. They provide a way to uniquely identify each record in a
table, and allow for efficient searching, sorting, and filtering of data.
In addition to defining the structure of a table, attributes can also have constraints or
rules that govern their behavior. For example, an attribute may have a "not null"
constraint, which ensures that the attribute cannot have a null or empty value. Other
constraints may include data type, length, and range checks.
Overall, attributes play an important role in defining the structure and behavior of a
database table, and are essential for effective data management and processing in
DBMS.

 Describe Relationship in DBMS and its types.

In database management systems (DBMS), a relationship refers to the association


between two or more tables or entities that are linked based on a common attribute
or key. Relationships help to establish the logical connections between tables and
enable efficient querying and manipulation of data.
There are three main types of relationships in DBMS:

 One-to-One Relationship: In a one-to-one relationship, each record in one table


is associated with only one record in the other table, and vice versa. For
example, a person may have only one passport, and a passport can belong to
only one person.

 One-to-Many Relationship: In a one-to-many relationship, each record in one


table is associated with one or more records in the other table, but each record
in the other table is associated with only one record in the first table. For
example, a customer can have multiple orders, but each order belongs to only
one customer.

 Many-to-Many Relationship: In a many-to-many relationship, each record in one


table is associated with one or more records in the other table, and each record
in the other table is associated with one or more records in the first table. For
example, students can enroll in multiple courses, and each course can have
multiple students.

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.

 Write what you know about DDL.

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.

 Write what you know about DCL.

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:

 GRANT: Used to grant a user or role access to a database object.


 REVOKE: Used to revoke access to a database object that was previously granted
using the GRANT command.
 DENY: Used to deny access to a database object even if it was granted using the
GRANT command.
 CREATE USER: Used to create a new database user.
 ALTER USER: Used to modify an existing user account.
 DROP USER: Used to delete a user account.

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.

 Write what you know about DML.

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:

 SELECT: Used to retrieve data from one or more tables in a database.


 INSERT: Used to insert new data into a table.
 UPDATE: Used to modify existing data in a table.
 DELETE: Used to remove data from a table.

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.

 Write what you know about TCL.

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?

SQL (Structured Query Language) is a programming language designed for managing


and querying data stored in a relational database management system (RDBMS). It
provides a standard way to create, read, update, and delete data from a database.
SQL is used to interact with databases in various ways, such as retrieving data from
specific tables or views, creating new tables and modifying existing ones, and setting
up constraints on data to ensure data integrity. SQL is widely used in the industry
and is a critical tool for managing and analyzing data in various applications.

 What are the subsets of SQL?

There are several subsets of 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.

 Transaction Control Language (TCL): This subset of SQL is used to manage


transactions in a database. It includes commands such as COMMIT and
ROLLBACK.

 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?

SAVEPOINT is a Transaction Control Language (TCL) command used in database


systems to mark a specific point in a transaction to which the transaction can be
later rolled back to. A SAVEPOINT can be used to create a nested transaction within a
larger transaction, allowing specific portions of a transaction to be undone without
affecting the entire transaction.
For example, suppose a database system is updating multiple rows in a table as part
of a transaction. With SAVEPOINT, the transaction can be broken up into smaller,
nested transactions. If an error occurs during the update of a specific row, the
transaction can be rolled back to the SAVEPOINT, undoing the changes made to that
specific row without affecting the other updates made within the transaction.
SAVEPOINT is a useful feature for complex transactions where it may be necessary to
undo only a portion of the transaction. By using SAVEPOINT, the database system
can maintain data integrity while still allowing flexibility in managing transactions.

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.

Wait for Graph

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.

Wound wait scheme

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.

 How many types of attributes are there?

In the context of database management systems, there are several types of


attributes. Some of the commonly recognized types of attributes are:

 Simple Attribute: A simple attribute is an attribute that cannot be further divided


into smaller components. For example, age, name, or address.

 Composite Attribute: A composite attribute is an attribute that can be divided


into smaller components. For example, an address attribute can be divided into
street, city, state, and zip code.

 Single-Valued Attribute: A single-valued attribute is an attribute that can have


only one value at a time. For example, the age of a person can have only one
value at a time.

 Multi-Valued Attribute: A multi-valued attribute is an attribute that can have


multiple values at a time. For example, the phone number of a person can have
multiple values.

 Derived Attribute: A derived attribute is an attribute whose value is derived from


other attributes. For example, the age of a person can be derived from the
person's date of birth.

 Key Attribute: A key attribute is an attribute that uniquely identifies an entity in


a database. For example, a social security number can be a key attribute for a
person entity.

 Foreign Key Attribute: A foreign key attribute is an attribute that refers to a


primary key attribute of another entity. It is used to establish relationships
between entities in a database.

 The main differences between DBMS and RDBMS are given below:
No DBMS RDBMS
.

1) DBMS applications store data as file. RDBMS applications store data in a tabular form.

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.

3) Normalization is not present in DBMS. Normalization is present in RDBMS.

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.

7) DBMS does not support distributed RDBMS supports distributed database.


database.

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.

9) Examples of DBMS are file systems, xml etc. Example of RDBMS are mysql, postgre, sql server, oracle etc.

You might also like