0% found this document useful (0 votes)
5 views

Database Systems

The document discusses fundamentals of database management systems including drawbacks of file systems for storing data such as data redundancy, inconsistency and difficulty accessing data. It also covers database architecture, concurrency issues and ensuring data integrity.

Uploaded by

x21e0day
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Database Systems

The document discusses fundamentals of database management systems including drawbacks of file systems for storing data such as data redundancy, inconsistency and difficulty accessing data. It also covers database architecture, concurrency issues and ensuring data integrity.

Uploaded by

x21e0day
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

FUNDAMENTALS OF DATABASE

CHAPTER – ONE Data inconsistency , on the other hand , refers to


the problem of having different version of the
same data. This problem arises when the same
INTRODUCTION TO DATABASE data appears in different files and one of the files
get updated while others do not. This results in
DBMS stands for Database Management System , different versions of the same data , which can
we can break it like this DBMS = Database + create confusion and lead to incorrect data
Management System. analysis and decision making. Inconsistency can
also occur when a file is updated by one user or
Database is a collection of data and Management application while other users are still using the
System is a set of programs to store and retrieve old versions of the same file. For example , if a
those data. Based on this we can define DBMS customer changes their address , the updated
like this :- “ DBMS is a collection of inter-related address needs to be reflected in all the files that
data and set of programs to store and access contain the customer’s information. If one file is
those data in an easy and effective manner” updated , and others are not , this creates
inconsistency in the data and can lead to
A database management system (DBMS) is system problems such as delivering products to the
software for creating and managing databases. wrong address.
The DBMS provides users and programmers with
a systematic way to create , retrieve , update and Difficulty in accessing data
manage data. A DBMS essentially serves as an
interface between the database and end users or In file-based systems, accessing data can be
application programs , ensuring that data is difficult and time-consuming, especially when the
consistently organized and remains easily amount of data grows. Since the data is stored in
accessible. separate files, the system needs to search through
all the files to find the relevant data, which can
The DBMS manages three important things : the be a slow and inefficient process. Moreover, if
data , the database engine that allows data to be the file names are not standardized or organized
accessed , locked and modified and the database in a logical manner, finding the correct file can
schema , which defines the database’s logical become a daunting task.
structure. These three foundational elements help
provide concurrency , security , data integrity Integrity Problems
and uniform administration procedures.
The issue of integrity problem comes in
In the early days , database applications were concurrent process , where multiple users may
built directly on top of file systems. access the same file simultaneously. If two users
try to modify the same data at the same time , it
Draw backs of using file systems to store can lead to data inconsistency , where one user’s
data changes overwrite the other user’s changes. This
can result in lost data , incorrect data or even
Data redundancy and inconsistency :- In file corrupt files.
based systems , data redundancy and
inconsistency are significant issues. Data Atomicity of updates
redundancy refers to the problem of storing the
same data in multiple files or records. This Atomic updates refers to the ability to modify
problem occurs when different users or multiple related pieces of data as a single ,
applications create their own file to store the indivisible operation , ensuring that the update is
same data. As a result , there are multiple copies either fully completed or note done at all. The
of the same data , which leads to storage space lack of atomic updates in file based systems can
wastage and makes data maintenance and updates lead to integrity problems , as incomplete or
a daunting task.
inconsistent data may be left behind if an update user 1’s changes , and user 1’s changes are lost.
is interrupted or fails halfway through. This is known as a lost update problem.

Atomicity of updates refers to the concept of File-based systems do not provide any
treating multiple related updates as a single, mechanisms for managing concurrent access to
complete operation. Imagine you have a banking files. Therefore it is up to the individual users to
coordinate their access to files to avoid these
application that needs to transfer money between
kinds of issues. This can be difficult and time
two accounts. Atomic updates ensure that either
consuming , especially in a large organization
the entire transfer is completed successfully, or with many users and many files. Additionally ,
no changes are made at all. file based systems do not provide any way to
enforce access control , so there is no way to
Let's say you transfer money from Account A to
prevent unauthorized access to files.
Account B. Without atomicity, if the update to
Account A succeeds but the update to Account B DBMS Architecture
fails halfway through, you could end up with an
inconsistent state. Account A would show the The architecture of DBMS depends on the
deducted amount, but Account B would still show computer system on which it runs. For example ,
in a client server DBMS architecture , the
the old balance. This can cause confusion and
database systems at a server machine can run
problems in managing finances.
several requests made by client machine. We will
To avoid such issues, atomic updates ensure that understand this communication with the help of
diagrams.
all related updates happen together or not at all.
In a multi-user environment, where multiple
There are three types of DBMS architecture :-
people may be accessing and modifying the same
data simultaneously, atomic updates are crucial. 1) SINGLE TIER ARCHITECTURE
They prevent conflicts and data corruption that
can occur when different users update the same In this type of architecture the database is readily
data at the same time. on the client machine , any request made by
client does not require a network connection to
Relational database systems offers support for perform the action on the database. For
atomic updates through the user of transactions , example , let’s say we want to fetch the records
which allows multiple related updates to be of employee from the database and the database
grouped together and treated as single , is available on your computer system , so the
indivisible operation. If a transaction fails , all request to fetch employee details will be done by
the changes made during the transaction can be your computer and the records will be fetched
rolled back , ensuring that the data remains from the database by your computer as well. This
consistent. type of system is generally referred as local
database system.
Concurrent access by multiple users

Concurrent access by multiple users is another


problem with file-based approaches. In a file
based-system , multiple users can access the same
file simultaneously , which can lead to issues
such as inconsistency , lost updates and even
data corruption. For example , consider a
scenario where two users try to update the same
file at the same time. User 1 opens the file ,
makes some changes , and saves the file.
However , before user 1 can close the file , user2
also opens the file and makes some changes ,
then saves the file. User 2’s changes overwrite
2) TWO TIER ARCHITECTURE :- 1. Instance: An instance refers to the actual
data stored in a database at a particular
In two tier architecture , the Database system is point in time. It represents a snapshot of
present at the server machine and the DBMS
the data that exists in the database at any
application is present at the client machine ,
given moment. It consists of all the
these two machines are connected with each
other through a reliable network as shown in the records, tables, and relationships that
above diagram. Whenever client machine makes a have been created and populated with
request to access the database present at server data.
using a query language like sql , the server
perform the request on the database and returns Think of the instance as the concrete
the result back to the client. The application representation of the data. It includes the specific
connection interface such as JDBC , ODBC are values stored in the database, such as the names,
used for the interaction between server and addresses, and other attributes of individuals in a
client. customer database. The instance can change over
time as new data is added, modified, or removed
from the database.

2. Schema: A schema, on the other hand,


defines the structure and organization of
the database. It represents the logical
blueprint or plan for how the data is
stored, organized, and accessed. The
schema includes the definitions of tables,
columns, relationships, constraints, and
other database objects.

In simpler terms, think of the schema as the


3) THREE TIER ARCHITECTURE :- In three tier
architecture , another layer is present between framework or the rules that govern how the data
the client machine and the server machine. In is stored and organized. It defines the structure
this architecture , the client application doesn’t of the database without specifying the actual data
communicate directly with the database systems values. The schema provides a blueprint for
present at the server machine , rather the client creating and maintaining the database and
application communicates with server application
ensures consistency and integrity in the data.
and the server application internally
communicates with the database system present The schema defines the types of data that can be
at the server. stored in the database, the relationships between
different tables, and the rules that govern data
validation and integrity. It serves as a guide for
developers, administrators, and users to
understand how the database is structured and
how to interact with it.

To summarize, an instance represents the actual


data stored in a database at a specific point in
INSTANCES AND SCHEMAS time, while a schema defines the structure and
organization of the database without including
In the context of a Database Management System the specific data values. Instances change over
(DBMS), instances and schemas refer to different time as data is added or modified, while schemas
aspects of organizing and managing data. provide the overall framework for how the data
is stored and accessed.
DBMS LANGUAGES executed as a single unit of work. TCL commands
are used to control the transactions by
committing or rolling back the changes made to
DBMS languages refer to the programming the database.
languages that are used to interact with databases
managed by database management systems COMMIT :- To persist the changes made by DML
(DBMS). These languages provide users with the commands in the database
ability to create , manipulate and query
databases. There are four types of DBMS ROLLBACK :- To roll back the changes made to
languages :- the database

1) Data Definition Language (DDL) :- It is used to


define the database schema. The schema describes DATA MODELS
the structure of the database and the
relationships between the tables. DDL commands In DBMS , a data model is a conceptual
are used to create , alter and delete database representation of the data structure that will be
objects such as tables. used to store , organize , and manage the data.
It defines how data will be organized , what
CREATE :- To create the database instance relationships will exist between different data
ALTER :- To alter the structure of database entities and what constraints will be applied to
DROP :- To drop database instances the data.
TRUNCATE :- To delete tables in a database
instance A data model provides a high level view of the
RENAME :- To rename database instances database system and allows database designers
DROP :- To drop objects from database such as and developers to create a blue print for the
tables database that can be used to guide the
implementation process. The most common data
2) Data Manipulation Languages (DML) :- models used in DBMS are hierarchical , network
model , relational , object oriented , ER-Model.
It is used to accessing and manipulate the data in
the database. DML commands are used to insert , 1) Hierarchical Model :- The hierarchical data
update and delete the data from the tables. These model organizes data in a tree like structure. In
commands allow the users to interact with the this model , each child record has only one
data in the database. parent but a parent record can have multiple
child records.

SELECT :- To read records from tables 2) Network Model :- The network model is a data
INSERT :- To insert records in to the tables model used in DBMS that is a modification of the
UPDATE :- Update the data in table(s) hierarchical model. In this model , data is
DELETE :- Delete all the records from the table represented in a graph-like structure with nodes
and edges. The nodes represent the data entities ,
3) Data Control Language (DCL) :- It is used to and the edges represent the relationship between
control the access to the database. DCL those entities.
commands are used to grant and revoke
permissions to the users and roles. These In the network model , each node have multiple
commands ensures the security of the data by parent and child nodes. This allows for more
controlling the access to the database objects. complex relationships between data entities to be
represented than in the hierarchical model. Nodes
GRANT :- To grant access to user can also be connected to multiple edges ,
REVOKE :- To revoke access from user allowing for more flexibility in representing
relationships.
4) Transaction Control Language :- It is used to
manage the transactions in the database. One of the key benefits of the network model is
Transactions are a set of operations that are its ability to represent complex data
relationships , however this complexity can also modeled. Each entity has attributes that describe
make it difficult to design and maintain. its properties.

3) Relational Model :- The relational data model Attributes :- Represented as ovals or circles
Is the most widely used data model in modern attached to the entity , attributes describe the
database management system. In this model , properties of an entity. For example , a student
data is organized in tables consisting of rows and entity might have attributes such as name ,
columns. student ID , and date of birth.

4) Object oriented Model :- The object oriented Relationship :- Represented as lines between
data model is designed to store complex data entities , relationships describe how entities are
types such as images , sound and video. In this related to each other. Relationships can be one to
model , data is organized in objects , which one , one to many , or many to many.
consist of attributes and methods. It provides a
high level of flexibility and supports complex SYMBOLS FOR ER-DIAGRAM
relationships between objects. It is mainly used in
multimedia applications. In an Entity-Relationship (ER) diagram, different
symbols are used to represent the components of
5) ER-Model :- The entity relationship model is
the database model. Here is a detailed description
conceptual data model that represents data as a
set of entities and their relationships. It is mainly of each symbol:
used to design database systems before they are
1. Rectangle: A rectangle is used to represent
implemented. The model is composed of three
an entity set, which represents a group or
components , entities , attributes and their
relationships. It provides a graphical collection of similar entities. An entity set
representation of the data model , which makes can represent a real-world object, such as
it easy to understand and communicate. a customer or an employee, or a concept,
such as an order or a product.
ENTITY RELATIONSHIP DIAGRAM
2. Ellipses: Ellipses are used to represent
An entity – relationship diagram (ERD) is a attributes, which are characteristics or
graphical representation of entities and their properties of an entity. Attributes describe
relationships to each other. ER diagrams are the specific details or information
typically used in software engineering and associated with an entity. For example, a
database design to help visually represent the customer entity may have attributes like
relationships between entities.
name, address, and phone number.

An entity is a person , a place , a thing or event 3. Diamonds: Diamonds are used to represent
that is relevant to the system being modeled. For relationship sets, which define the
example , in a university database , entities
associations or connections between entity
might include students , courses , instructors ,
sets. Relationship sets describe how
and departments.
entities from different entity sets are
A relationship is an association between entities. related or linked to each other. For
For example in the university database , there example, a relationship set can represent
might be a relationship between students and the "works for" relationship between
courses , where a student can take many courses employees and departments.
and a course can have many students.
4. Lines: Lines are used to represent the
ER diagrams typically include the following connections between different components
components :- in an ER diagram. They are used to
connect attributes to entity sets and entity
Entities :- Represented as rectangles , entities are
sets to relationship sets. For example, a
the objects that exist with in the system being
line can connect an attribute like "age" to
an entity set like "student", indicating Components of a ER diagram
that "age" is an attribute of the "student"
entity. 1) In entity – in relationship diagrams a strong
entity is an entity that can exist independently ,
5. Double Ellipses: Double ellipses are used where as a weak entity is an entity that can not
to represent multi-valued attributes. A exist being associated with a specific strong
multi-valued attribute is an attribute that entity.
can have multiple values for a single
entity. For example, an entity representing A strong entity is also referred to as a regular
entity because it is independent and has its own
a student may have a multi-valued
unique identifier. For example , in a database for
attribute like "hobbies" that can have
a university , a student is a strong entity because
multiple hobbies associated with it. they have their own unique identifier such as a
student ID number.
6. Dashed Ellipses: Dashed ellipses are used
to represent derived attributes. A derived
On the other hand a weak entity is dependent on
attribute is an attribute whose value can a strong entity and can not exist without it. A
be derived or calculated based on other weak entity does not have its own unique
attributes. It is not directly stored in the identifier and instead relies on the identifier of
database but can be derived from other the related strong entity. For example , in the
attributes. For example, the age of a same university database , a course offering may
be a weak entity because it can not exist without
person can be derived from their birth
being associated with a specific department ,
date.
which is a strong entity.
7. Double Rectangles: Double rectangles are
Weak entities are typically represented in ER
used to represent weak entity sets. A
diagrams with a double rectangle , while strong
weak entity set is an entity set that
entities with a single rectangle. The relationship
cannot be uniquely identified by its own between strong entity and a weak entity is
attributes. It depends on the existence of represented with a solid diamond shape , with
a related entity set called the owner the weak entity being connected to the strong
entity set. For example, a "dependent" entity with a line.
entity set may be a weak entity set that
For example , a bank account can not be
depends on the "employee" entity set as
uniquely identified with out knowing the bank to
its owner.
which the account belongs , so bank account is a
weak entity.

CHAPTER -TWO :- DATABASE DESIGN

CHAPTER – THREE :- RELATIONAL


MODEL 2) Attribute

An attribute describes the property of an entity.


CHAPTER – FOUR :- RELATIONAL An attribute is represented as Oval in an ER
ALGEBRA diagram. There are four types of attributes.

1) Key attribute :- A key attribute is an attribute


that uniquely identifies an entity instance with in
an entity set. In other words , a key attribute is
used to distinguish one entity from another , For
example , in a customer entity set , a customer
ID might be the key attribute.

A key attribute is represented by oval same as


other attributes however the text of the key
attribute is underlined.

3) RELATIONSHIP

A relationship is represented by a diamond shape


in ER diagram. It shows the relationship among
entities. There are four types of relationships :-

1) One to one
2) One to many
3) Many to one
4) Many to many

2) Composite Attribute :- A composite attribute is


1) One to One Relationship (1:1)
an attribute that is made up of multiple smaller
attributes. For example , a person’s address might
This type of relationship occurs when one
be composed of multiple smaller attributes , such
instance of an entity is associated with only one
as street , city , state and zip code.
instance of another entity. For example , one
student is assigned to only one locker , and
each locker is assigned to only one student.

2) One to Many (1:N) :- This type of relationship


occurs when one instance of an entity are
associated with many instances of another entity.
3) Multi-valued attribute :- A multi valued
For example , one department may have many
attribute is an attribute that can have more than
employees , but each employee is associated with
one value for a single entity instance. For
only one department.
example , a person might have multiple phone
numbers , such as home phone and a work
phone. It is represented by double ovals in an ER
diagram.

4) Derived Attribute :- A derived attribute is an


attribute that is derived or calculated from other
attributes. For example , a person’s age can be
derived from their date of birth.

3) Many to one (N:1) :- This type of relationship


It is represented by dashed oval in an ER
occurs when many instances of an entity are
diagram.
associated with only one instance of another
entity. For example , many employees work in WHAT DOES IT MEAN BY CONSTRAINT IN
one department , but each department is DATABASE ?
associated with only one manager.
In a database, a constraint is like a rule or
restriction that is applied to make sure the data
stored in the database is accurate and consistent.
Constraints help to keep the data in good quality
over time. They are enforced by the database
system, which makes sure that the rules are
followed and prevents any mistakes or
inconsistencies.

There are different types of constraints that can


4) Many to Many (N:N) :- This type of be used in a database:
relationship occurs when many instances of an
1. Primary Key Constraint: This makes sure
entity are associated with many instances of
another entity. For example , many students can that each row in a table is uniquely
enroll in many courses , and each course can identified by a specific column or set of
have students enrolled in it. columns. It means that there can't be any
duplicate rows with the same
identification.

2. Foreign Key Constraint: This is used to


link two tables together by connecting a
column in one table to the primary key
column in another table. It makes sure
that the values in the linked column are
valid and correspond to the values in the
primary key column.
RELATIONAL MODEL CONCEPT 3. Check Constraint: This defines a rule that
limits the values that can be entered into
The relational model is a data model used to
a column. It can be used to validate the
organize and represent data in a structured and
data and ensure that it falls within a
efficient way. It is based on the concept of
relations or tables , where each row represents specific range or follows certain rules.
an entity or record and each column represents a
4. Not Null Constraint: This simply says that
specific attribute or characteristic of that entity.
a column must always have a value and
The relationships between tables are established can't be left empty or null. It ensures that
through common attributes called keys , which important information is always provided
allow for the creation of complex queries and and not missing.
reports that can retrieve and analyze data from
multiple tables at once. 5. Unique Constraint: This guarantees that
no two rows in a table have the same
The relational model also includes a set of values in a specific column or set of
constraints such as primary keys and foreign keys columns. It makes sure that each value is
, that ensure the accuracy and consistency of the unique and there are no duplicates.
data stored in the tables.
These constraints help to maintain the quality
and integrity of the data in the database,
preventing mistakes and making sure that the
data is reliable and accurate.
THE DIFFERENCE BETWEEN PRIMARY KEY one to many relationship between the two
AND UNIQUE KEY tables , where each customer can have multiple
orders.
A primary key and a unique key are both types
Table :- Orders
of constraints used in a database to ensure the
uniqueness of values in a column or set of
Order Id Customer Id Order Date Total
columns. However, there are some differences
between them: 1 101 2022-03-15 500.00
2 102 2022-03-16 750.0
Purpose:
3 101 2022-03-17 1500.00
• Primary Key: The primary key is a
column or set of columns that uniquely 4 103 2022-03-18 200.00
identifies each row in a table. It is used
In this example , the orders table has a foreign
to establish the identity of a record and
key column called “Customer ID” which refers to
ensure its uniqueness within the table.
the primary key column “CustomerID” in the
• Unique Key: The unique key is also used customers table. The “CustomerID” column in
to ensure the uniqueness of values in a the orders table is used to establish a link or
column or set of columns. It prevents relationship between the orders and customers
duplicate values from being entered but tables.
does not necessarily serve as the primary
For each order in the Orders table , the
identifier for the record.
“customerID” column specifies the customer who
placed the order. In this case , orders 1 , 3 , and
PRIMARY KEY AND FOREIGN KEY 2 were placed by customers 101 , 101 , and 102
respectively.
In a relational database , a primary key and
foreign key are two types of constraints that are The foreign key constraint ensures that the values
used to establish and enforce relationships in the “CustomerID” column in the orders table
between tables. correspond to valid values In the “CustomerID”
column in the customers table. This helps to
A primary key is a unique identifier for each row maintain data consistency and accuracy across
in the table , It is a column or a combination of two tables.
columns that uniquely identifies each record in
the table. The primary key is used to enforce Foreign keys are important component of a
data integrity. It also serves as a reference point relational database that help to establish and
for foreign keys in other tables. maintain relationships between tables. They
ensure that data is consistent and accurate , and
A foreign key is a column or a combination of allow for efficient retrieval and manipulation of
columns in a table that refers to the primary key data.
of another table. It establishes a link or
relationship between two tables. The foreign key PROPERTIES OF RELATIONS
ensures that the data in the table is consistent
and accurate by enforcing referential integrity. ➢ Name of the relation is distinct from all
This means that a foreign key value must exist in other relations
the referenced table’s primary key column.
➢ Each relation cell constraints exactly one
For example , consider two tables : Customers atomic (single) value
and Orders. The customers table has a primary
key column called “CustomerID” , the orders ➢ Each attribute contains a distinct name
table has a foreign key column called
“CustomerID” that references the “Customer ID” ➢ Tuples has no duplicate value
column in the customers table. This establishes a
➢ Order of tuple can have a different The operations in relational algebra include :-
sequence
1) Selection :-
Uniqueness :- Each tuple in a relation is unique ,
meaning that no two tuples in the relation are In relational algebra, the selection operator is a
exactly the same. This is enforced by the primary unary operator that is used to select a subset of
key constraint , which ensures that each tuple is tuples from a relation that satisfy a specific
uniquely by a specific attribute or combination of condition. The condition is specified using
attributes. predicate which is a boolean expression that
evaluates to True or False.
Atomicity – each attribute in a relation represents
a single , indivisible value. This means that each The selection operator is represented by the
attribute can not be further divided in to smaller sigma symbol (σ) and is used in the following
parts. For example, a "Name" attribute would way :- σ<condition>® , Where σ represents the
represent a single person's name and not a selection operator , <condition> represents the
combination of multiple names. predicate used to select tuples and R represents
the input relation.
Order :- The tuples in a relation have no inherent
order , meaning that they can be accessed in The predicate P is used as a propositional logic
any order without affecting the meaning of the formula which may use connectors like : AND ,
relation. OR , and NOT. These relational can use as
relational operators lime =, ≠, ≥, <, >, ≤

RELATIONAL ALGEBRA For example , consider the following relation


named “Employees”
Relational algebra is a mathematical notation or
formal language used to represent and manipulate
ID Name Age Salary
data in a relational database. It consists of a set
of operators that can be applied to relations 1 John Doe 30 50000
(tables) to produce new relations. These operators
2 Jane Smith 25 40000
are similar to the operators in algebra , such as
addition and multiplication. 3 Bob Jones 40 60000
4 Alice Lee 35 55000
The operators in relational algebra can be
classified in to two groups :-
To select all employees with a salary greater than
1) Unary Operators :- These operators take a 50000 , we can use the selection operator as
single relation as input and produce a new follows :-
relation as output. Examples of unary operators
include selection and projection. σ (Salary > 50000) (Emplyees)

2) Binary Operators :- These operators take two The result of this operation would be a new
relations as input and produce a new relation as relation that contains the following tuples.
output. Examples of binary operators include join
and set operations such as union , intersection ID Name Age Salary
and difference. 3 Bob Jones 40 60000

By combining these operators , complex queries 4 Alice Lee 35 55000


can be constructed to retrieve and manipulate
data from a relational database. Relational In this example , the selection operator has been
algebra provides a formal and precise way of used to select a subset of tuples from the
expressing these operations and is the basis for “Employees” relation that meet the specified
many relational database management systems. condition. The resulting relation contains only
those tuples where the “salary” attribute is
greater than 50000.
Example :- σ (A=B ^ D > 5) (R) To project only the “Name” and “Email”
attributes from the “Customers” relation , we
can use the projection operator as follows :-

π(Name, Email)(Customers)

The result of this operation would be a new


relation that contains the following attribute

Name Email
John Smith [email protected]
m

2) Projection Jane Doe [email protected]


Bob Jones [email protected]
In relational algebra , the projection operator is a
unary operator that is used to select a subset of Alice Lee [email protected]
attributes from a relation and create a new
relation that contains only those attributes. The In this example , the projection operator has
projection operator is represented by the Greek been used to select a subset of attributes from
letter pi (π). the “customers” relation and create a new
relation that contains only those attributes. The
The projection operator is used in the following resulting relation contains only the “Name” and
way :- “Email” attributes and the other attributes have
been removed.
π<attribute list>®
Example :- π (A , C) (R)
Where π represent the projection operator ,
<attribute list> represents the list of attributes to
be projected , and R represents the input
relation.

For example , consider the following named


“Customers”

ID Name Age Gender Email


1 John 30 Male john.smi
Smith th@exa
mple.co
m
2 Jane 25 Female john.smi
Doe th@exa
mple.co
m
3 Bob 40 Male john.smi
Jones th@exa
mple.co
m 3) Union
4 Alice 35 Female john.smi
Lee th@exa In relational algebra , the union operator is a
mple.co binary operator that combines two relations with
the same schema and creates a new relation that
contains all tuples from the input relations. The In this example , the union operator has been
union operator is represented by the symbol u. used to combine the “Employees” and
“Managers” relations in to a single relation that
The union operator is used in the following way contains all tuples from both relations. The
resulting relation contains all attributes from both
R U S , where R and S are the input relations. input relations and tuples are not duplicated.
For example , consider the following two
relations named “Employees” and “Managers”. In the union operator , both of the input
relations must have the same number of
Employees :- attributes and the attributes must be of
compatible data types.
ID Name Age Salary
For example , if one relation has an attribute of
1 John Doe 30 50000 type integer then the other relation must also
2 Jane Smith 25 40000 have an attribute of type integer at the same
position , if the data types are not compatible ,
3 Bob Jones 40 60000
the union operation may result In an error or
4 Alice Lee 35 55000 undefined behavior.

Managers In addition , the attributes must be in the same


order in both relations , for example if the first
attribute in one relation is “ID” , then the first
ID Name Age Department
attribute in the other relation must also be “ID”.
5 Sarah 45 Sales The attribute names can be different , but the
Johnson position and data type must be the same.
6 Tom 50 Marketing
It is also worth nothing that the union operator
Jackson
removes duplicates from the resulting relation. If
both input relations have the same tuple , it
To combine the “Employees” and “Managers” appears only once in the output relation.
relations in to a single relation , we can use the
union operator as follows :- Example :-

Employees U Managers Deposit Relation

The result of this operation would be a new


Customer Name Account Number
relation that contains all tuples from both input
relations. Johnson A-101
ID Name Age Salary Departm Smith A-121
ent
Mayes A-321
1 John 30 50000
Doe Turner A-176

2 Jane 25 40000 Johnson A-273


Smith Jones A-472
3 Bob 40 60000 Lindsay A-284
Jones
4 Alice 35 55000 Borrow Relation
Lee
5 Sarah 45 sales Customer Name Loan No
Johnson Jones L-17
6 Tom 50 Marketin Smith L-23
Jackson g
Hayes L-15 only the tuples that appear in both input
relations , the set intersection operator is
Jackson L-14 represented by the symbol n. The set intersection
Curry L-93 operator is used in the following way :-

Williams L-17
R ∩S

Where R and S are the input relations.


Input :- Deposit Relation U Borrow Relation
For example , consider the following two
Customer Name Account No Loan No relations named “A” and “B”
Johnson A-101
A
Smith A-121 L-23
Mayes A-321 ID Name Age

Turner A-176 1 John Doe 30

Johnson A-273 2 Jane Smith 25

Jones A-472 L-17 3 Bob Jones 40

Lindsay A-284 4 Alice Lee 35

Hayes L-15
B
Jackson L-14
ID Name Age
Curry L-93
2 Jane Smith 25
Williams L-17
4 Alice Lee 35
6 Tom 50
Input :- ∏ CUSTOMER_NAME (BORROW) ∪ ∏
Jackson
CUSTOMER_NAME (DEPOSITOR)

To find the intersection of the “A” and “B”


Customer Name
relation , we can use the set intersection as
Johnson follows :

Smith
A ∩ B
Mayes
The result of this operation would be a new
Turner
relation that contains only the tuples that appear
Jones in both input relations.
Lindsay
ID Name Age
Hayes
2 Jane Smith 25
Jackson
4 Alice Lee 35
Curry
Williams In this example , the set intersection operator has
been used to find the common tuples in both
4 Set Intersection input relations. The resulting relation contains
only the tuples that appear in both relations.
In relational algebra , the set intersection
operator is a binary operator that combines two
relations and returns a new relation containing
5) Set Difference The set difference operator is a useful tool for
finding the elements that are unique to a
In relational algebra , the set difference operator particular set of data. It is widely used in SQL
is a binary operator that combines two relations and other query languages to construct complex
and returns a new relation containing only the queries that can extract meaningful insights from
tuples that appear in the first relation but not in large datasets.
the second relation. The set difference operator is
represented by the symbol :- R – S 6) Cartesian Product

Where R and S are the input relations. For In relational algebra , the Cartesian product is a
example , consider the following two relations binary operator that combines two relations and
named “A” and “B”. returns a new relation that contains all possible
combinations of tuples from both input relations.
A : The Cartesian product operator is represented by
the symbol x.
ID Name Age
The Cartesian product operator is used in the
1 John Doe 30 following way :-
2 Jane Smith 25
R X S
3 Bob Jones 40
4 Alice Lee 35 Where R and S are the input relations. For
example , consider the following two relations
B. named “A” and “B”.

A
ID Name Age
2 Jane Smith 25 ID Name Age
4 Alice Lee 35 1 John Doe 30
6 Tom Jackson 50 2 Jane Smith 25

To find the set difference of the “A” and “B”


relations we can use the set difference operator B
as follows :-
ID City Country
A – B
1 London UK
The result of this operation would be a new
2 New York USA
relation that contains only tuples that appear in
relation “A” but not in relation “B”. 3 Paris France

ID Name Age To find the Cartesian product of the “A” and


“B” relations , we can use the Cartesian product
1 John Doe 30
operator as follows :-
3 Bob Jones 40
A x B
In this example , the set difference operator has
been used to find the tuples that appear in The result of this operation would be a new
relation “A” but not in relation “B”. The relation that contains all possible combinations of
resulting relation contains only the tuples that are tuples from both input relations
unique to relation “A”.
ID Name Age City Country To change the name of the “Employees” relation
to “Staff” , we can use the rename operator as
1 John Doe 30 London UK follows
1 John Doe 30 NewYork USA
ρ (Staff)(Employees)
1 John Doe 30 Paris France
2 Jane Smith 25 London UK The result of this operation would be a new
2 Jane Smith 25 NewYork USA relation named “Staff” that has the same
attributes an tuples as the original relation.
2 Jane Smith 25 Paris France
To change the name of the “salary” attribute to
In this example , the Cartesian product operator “Wage” in the “Employees” relation , we can
has ben used to find all possible combinations of use the rename operator as follows :-
tuples from both input relations. The resulting
relation contains all attributes from both input ρ(ID, Name, Age, Wage)(Employees)
relations and all possible combinations of tuples.
The result of this operation would be a new
The Cartesian product operator is a powerful tool relation that has the same tuples as the original
for finding all possible combinations of data from relation , but the “salary” attribute has been
different relations. It is widely used in SQL and renamed to “Wage”.
other query languages to construct complex
queries that can extract meaningful insights from In this example , the rename operator has been
large datasets. used to change the name of the relation and its
attributes. The resulting relation contains the
same data as the original relation , but with
7) Rename Operation different names for the relation or its attributes.

In relational algebra , the rename operations is a 8) Join Operation


unary operator that is used to change the name
of a relation or its attributes. The rename In relational algebra , the join operation is a
operation is represented by the Greek Letter binary operator that combines two relations based
rho(ρ). The rename operation is used in the on a common attribute and creates a new
following way :- relation that contains all possible combinations of
tuples from both input relations that match the
condition. The join operator is a fundamental
ρ<new relation or attribute names>®
operation in relational databases , and it is
widely used in SQL and other query languages to
Where ρ represents the rename operator <new
extract meaningful information from large
relation or attribute name> represents the new
datasets.
names for the relation or its attributes , and R
represents the input relation.
The join operator is used in the following way :-

For example :- consider the following relation


R ⋈<condition> S
named “Employees”
Where R and S are the input relations , and
ID Name Age Salary <condition> is the condition that the tuples must
satisfy in order to be included in the resulting
1 John Doe 30 50000 relation. The condition is typically based on a
2 Jane Smith 25 40000 common attribute that appears in both input
relations.
3 Bob Jones 40 60000
For example , consider the following two
4 Alice Lee 35 55000 relations named “Employees” and “Departments”
Employees :- In this example , the join operator has been used
to combine the “Employees” and “Departments”
ID Name Age Salary Departm relations based on the common “Department ID”
ent Id attribute. The resulting relation contains all
possible combinations of tuples where the
1 John 30 50000 1 “DepartmentID” in the “Employees” relation
Doe matches the “ID” in the “Departments ”
2 Jane 25 40000 2 relation.
Smith
There are several types of join operations ,
3 Bob 40 60000 1
including inner join , left join , right join , and
Jones
full outer join. These operations differ in how
4 Alice 35 55000 3 they handle tuples that do not have a matching
Lee value in the other input relation.

Departments Types Of Join Operation

ID Name An inner join is a type of operation in a


relational database that combines two tables
1 Sales
based on a common attribute and returns only
2 Marketing
the matching records from both tables. It is one
3 Operations of the most commonly used join operations in
SQL and helps to retrieve related information
To join the “Employees” and “Departments” from multiple tables.
relations based on the “DepartmentID” attribute ,
we can use the join operator as follow :- Imagine you have two sets of data, let's call them
Set A and Set B. Each set contains information
Employees ⋈ Department ID = ID Departments about different things, but there may be some
common information between them. Inner join
The result of this operation would be a new
helps you find the common information between
relation that contains all possible combinations of
Set A and Set B.
tuples from both input relations where the
“Department ID” in the employees relation To perform an inner join, you compare a specific
matches the “ID” in the “Departments ” attribute (a characteristic or property) in each
relation.
element of Set A with the corresponding attribute
in Set B. For example, you might compare the
ID Name Age Salary Departm Name
ent Id "ID" attribute in Set A with the "ID" attribute in
Set B.
1 John 30 50000 1 Sales
Doe When comparing these attributes, you look for
3 Bob 40 60000 1 Sales matching values. If the values in the attribute
Jones match between an element in Set A and an
2 Jane 25 40000 2 Market element in Set B, those two elements are
Smith ing considered a match. Only the matching elements
are included in the result.
4 Alice 35 55000 3 Operati
Lee ons Any elements that don't have a matching value in
the other set are excluded from the result. So, if
an element in Set A doesn't have a corresponding
match in Set B, it won't be included, and vice
versa.
The purpose of an inner join is to find the another group, and it ensures that you don't miss
common records or relationships between the two any friends from the first group, even if they
sets. It allows you to extract only the elements don't have any connections in the second group.
that have matching values in the specified
A right join is a type of join operation in SQL
attribute.
that combines records from two tables based on a
To represent an inner join, you use the symbol specified condition and includes all tuples from
"⋈" (which represents the join operation) the right (second) table, along with matching
followed by a condition that specifies which tuples from the left (first) table. If there is no
attributes to compare. For example, you might match in the left table for a tuple in the right
write Set A ⋈ ID = ID Set B to perform an inner table, NULL values are used for the attributes of
join based on the "ID" attribute. the left table in the result.

A left join is a type of join operation in a Imagine you have two groups of friends, Group A
relational database that combines two tables and Group B. This time, you want to find out
based on a common attribute and returns all the which friends from Group B also belong to Group
records from the left (or first) table and the
A. So, you decide to perform a right join.
matching records from the right (or second) table.
If there is no match in the right table, NULL In a right join:
values are used for the attributes of the right
table in the result set. • You take all your friends from Group B
and write down their names.
Imagine you have two groups of friends, Group A • Then, you look at Group A and see if any
and Group B. You want to find out which friends of your friends from Group B are also
from Group A also belong to Group B. So, you there.
decide to perform a left join. • If a friend from Group B is in Group A,
you write down their name next to their
In a left join:
friend from Group B.
• You take all your friends from Group A • But if a friend from Group B is not in
and write down their names. Group A, you leave that space empty, like
• Then, you look at Group B and see if any a blank space.
of your friends from Group A are also
The right join ensures that you include all your
there.
friends from Group B, even if they don't have
• If a friend from Group A is in Group B,
any friends in Group A. So, the final list will
you write down their name next to their
have the names of all your friends from Group B,
friend from Group A.
and if they have friends in Group A, their names
• But if a friend from Group A is not in
will be written next to them. If they don't have
Group B, you leave that space empty, like
any friends in Group A, the space next to their
a blank space.
name will be empty.
The left join ensures that you include all your
In essence, the right join is similar to the left
friends from Group A, even if they don't have
join, but it focuses on the right (second) group
any friends in Group B. So, the final list will
instead of the left (first) group. It helps you see
have the names of all your friends from Group A,
which friends from one group also belong to
and if they have friends in Group B, their names
another group, and it ensures that you don't miss
will be written next to them. If they don't have
any friends from the second group, even if they
any friends in Group B, the space next to their
don't have any connections in the first group.
name will be empty.
That's how a right join works! It allows you to
That's how a left join works! It helps you see
find the connections between friends in different
which friends from one group also belong to
groups, considering the right group as the Full Functional Dependency: A full functional
primary focus. dependency occurs when an attribute is
functionally dependent on the entire combination
A full outer join is a type of join operation in
of values in the primary key, and not on any
SQL that combines records from two tables based
subset of the key. This means that the attribute
on a specified condition and includes all tuples
depends on all the attributes of the primary key,
from both tables, whether they have a match or
and removing any attribute from the key would
not. It ensures that no data is left out and
break the dependency. In simpler terms, the
includes both the matching tuples and the non-
value of the attribute is determined by the entire
matching tuples from both input tables.
primary key. If any proper subset of the primary
To understand a full outer join, let's imagine two key can determine the attribute, it is not a full
tables: Table A and Table B, each containing functional dependency.
different sets of data. A full outer join between
Example: Consider a table with attributes
these tables works as follows:
(columns) Student ID, Course ID, and Course
1. Take all the tuples from Table A and Instructor. If Course Instructor is fully
write down their attributes. functionally dependent on the combination of
2. Look at Table B and check if any tuples Student ID and Course ID, it means that for a
have matching values based on the given Student ID and Course ID, there is a
specified condition. unique Course Instructor associated with it.
3. If a tuple from Table A matches a tuple
Partial Functional Dependency: A partial
from Table B, write down the attributes
functional dependency occurs when an attribute is
of both tuples together in the result set.
functionally dependent on only a part of the
4. If a tuple from Table A doesn't find a
primary key, and removing any attribute from the
match in Table B, still write down its
key would still maintain the dependency. This
attributes in the result set, using NULL
means that the attribute depends on a subset of
values for the attributes from Table B.
the primary key rather than the entire key.
5. Take all the tuples from Table B that
Partial functional dependencies can lead to data
didn't find a match in Table A and write
anomalies and are undesirable in database design.
down their attributes in the result set,
using NULL values for the attributes from Example: Continuing with the previous example,
Table A. if Course Instructor depends only on the Student
ID and not on the Course ID, it would represent
In simple terms, a full outer join combines the
a partial functional dependency. In this case, the
data from both tables, ensuring that all tuples
Course Instructor is determined by the Student ID
from both tables are included in the result. It
alone, irrespective of the Course ID.
helps you find relationships between data in the
two tables and provides a complete view of the Transitive Dependency: A transitive dependency
data, regardless of matching or non-matching occurs when an attribute is functionally
values. dependent on another non-key attribute rather
than directly on the primary key. In simpler
TYPES OF FUNCTIONAL DEPENDENCY
terms, the value of an attribute depends on
Functional dependency is a concept in database another non-key attribute, which, in turn,
normalization that describes the relationship depends on the primary key. Transitive
between attributes (columns) in a table. It defines dependencies can also lead to data anomalies and
how the values of one or more attributes are undesirable in a well-normalized database.
determine the values of other attributes. In other Example: Suppose we have a table with attributes
words, it specifies the dependencies between (columns) Student ID, Course ID, and Course
attributes based on their values.
Instructor's Department. If the Course Instructor's For example, let's consider a table called
Department depends on the Course ID, and the "CUSTOMERS" with columns like ID, NAME,
Course ID depends on the Student ID, then there AGE, ADDRESS, and SALARY. Each row in this
is a transitive dependency between the Student ID table represents a customer's information, such as
and the Course Instructor's Department. The their ID, name, age, address, and salary.
Course Instructor's Department indirectly depends
A field is a column in a table that holds specific
on the Student ID through the Course ID.
information about each record. In our example,
Identifying and eliminating partial functional the ID, NAME, AGE, ADDRESS, and SALARY are
dependencies and transitive dependencies are the fields of the CUSTOMERS table.
important steps in achieving higher normal forms,
A record, also known as a row, is an individual
such as the Boyce-Codd Normal Form (BCNF) or
entry or a set of data in a table. Each record
the Third Normal Form (3NF), which ensure a
contains values for each field. In our example,
well-structured and non-redundant database
each row in the CUSTOMERS table represents a
design.
customer's information, such as their ID, name,
age, address, and salary.

A column is a vertical entity in a table that


STRUCTURED QUERY LANGUAGE (SQL)
contains information for a specific field. It
SQL is like a special language that computers use represents all the values for that particular field
to talk to databases. Databases are like big across all records in the table. For example, the
organized storage places for information. With ADDRESS column in the CUSTOMERS table holds
SQL, we can create databases, add or remove the location descriptions, such as Ahmedabad,
information, and ask the database questions to Delhi, Kota, etc.
get the data we need.

Why do we use SQL? Well, it helps us access


and manage data in databases. We can describe
the data we want, like asking for specific
information about a person or a product. We can
also define how the data should be organized and
change it when needed.

RDBMS (Relational Database Management System)


is a type of database management system that is
based on the relational model. It is the
A NULL value in a table refers to a field that
foundation for modern database systems like MS
appears to be blank or has no value. It is
SQL Server, Oracle, and MySQL. RDBMS helps
different from a zero value or a field with spaces.
manage and organize large amounts of data
A field with a NULL value means that it has not
efficiently.
been filled or does not contain any specific value.
In an RDBMS, data is stored in database objects
Understanding these concepts helps us organize
called tables. A table is like a collection of
and manipulate data effectively in relational
related data entries. It consists of columns (also
databases using SQL.
known as fields) and rows (also known as
records). Each row represents a single entry or
record in the table, and each column represents a SQL CONSTRAINTS
specific piece of information about the records.
Constraints are the rules enforced on data
columns on table. These are used to limit the
type of data that can go into a table. This
ensures the accuracy and reliability of the data in • The UNIQUE Constraint prevents two
the database. Constraints could be column level records from having identical values in a
or table level. Column level constraints are particular column. In the CUSTOMERS
applied only to one column, whereas table level
table, for example, you might want to
constraints are applied to the whole table.
prevent two or more people from having
• NOT NULL Constraint: The NOT NULL identical age.
constraint ensures that a column cannot
have a NULL value. It enforces that the
column must always contain a value. This
constraint is applied at the column level
and prevents inserting or updating a row
with a NULL value in that column.

• PRIMARY KEY Constraint: The PRIMARY


• DEFAULT Constraint: The DEFAULT
KEY constraint uniquely identifies each
constraint provides a default value for a
row/record in a database table. It ensures
column when no value is specified during
that the column or combination of
an INSERT statement. If a column with a
columns specified as the primary key has
DEFAULT constraint is not explicitly given
a unique value for every record in the
a value, it will be assigned the default
table. A primary key cannot contain NULL
value defined for that column. This
values or duplicate values. Typically, a
constraint is useful when you want to set
primary key is a single column, but it can
a standard value for a column if no
also be a combination of columns.
specific value is provided.

• UNIQUE Constraint: The UNIQUE • FOREIGN KEY CONSTRAINT: The


constraint ensures that all values in a FOREIGN KEY constraint establishes a
column are unique, meaning no duplicate relationship between two tables by linking
values are allowed. Each value in the the primary key of one table to a column
column must be distinct. The UNIQUE (known as a foreign key) in another table.
constraint can be applied to one or more It ensures referential integrity by
columns, forming a unique combination of enforcing that the values in the foreign
values across those columns. This key column must match the values in the
constraint helps maintain data integrity by referenced primary key column. This
preventing duplicate entries.
constraint maintains the consistency and manageable tables while establishing relationships
relationships between related tables.
between them.

Normalization is based on a set of rules called


normal forms, which define specific conditions
that a database table should meet. The most
commonly used normal forms are the First
Normal Form (1NF), Second Normal Form (2NF),
and Third Normal Form (3NF). Each normal form
has its own criteria that must be satisfied for the
table to be considered normalized.

The process of normalization involves analyzing


the data and identifying relationships and
dependencies between different attributes.
Redundant data is removed by splitting tables
• CHECK Constraint: The CHECK constraint and establishing relationships using primary keys
ensures that the values in a column and foreign keys. This ensures that data is stored
satisfy certain conditions or expressions. It efficiently, avoids data inconsistencies, and
allows you to define specific rules or reduces the chances of anomalies during data
conditions that the data in the column manipulation.
must meet. If a row violates the condition
By normalizing a database, you can achieve
specified by the CHECK constraint, it will
benefits such as reduced data duplication,
not be inserted or updated. This
improved data integrity, simplified data
constraint helps enforce data integrity by
maintenance, and enhanced query performance.
restricting the range or values allowed in
Normalization helps create a well-structured and
a column.
organized database that can adapt to changes and
support efficient data retrieval and manipulation
operations.

How do we determine whether a table isn’t


normalized enough – in other words, how do we
determine if there’s a danger that redundant data
could creep into the table? Well, it turns out that
there are sets of criteria we can use to assess the
level of danger. These sets of criteria have names
like “first normal form”, “second normal form”,
DATABASE NORMALIZATION
“third normal form”, and so on.

Normalization is a process in database design that


Think of these normal forms by analogy to safety
helps organize and structure data efficiently. The
assessments. We might imagine an engineer doing
goal of normalization is to eliminate data
a very basic safety assessment on a bridge. Let’s
redundancy, improve data integrity, and ensure
say the bridge passes the basic assessment, which
logical data dependencies. It involves breaking
means it achieves “Safety Level 1: Safe for
down a large table into smaller, more
Pedestrian Traffic” That gives us some comfort,
but suppose we want to know if cars can safely Members
drive across the bridge? To answer that question, John
Paul
we need the engineer to perform an even stricter
George
assessment of the bridge. Let’s imagine that the
Ringo
engineer goes ahead and does this stricter
assessment, and again the bridge passes,
While the names are correctly listed, the order of
achieving “Safety Level 2: Safe for Cars”. If even
the rows may vary. One possible order could be
this doesn’t satisfy us, we might ask the engineer
John, Paul, George, and Ringo, while another
to assess the bridge for “Safety Level 3: Safe for
order could be Paul, John, Ringo, and George.
Trucks.” And so on. The normal forms of The variation in row order doesn't affect the fact
database theory work the same way. If we that these are the members of the band, and
discover that a table meets the requirements of both orderings are equivalent.
first normal form, that’s a bare minimum safety However, in a relational database, the order of
guarantee. If we further discover that the table the rows is not significant. The database
meets the requirements of second normal form, management system does not guarantee any
that’s an even greater safety guarantee. And so specific order when retrieving data from the table
on. unless explicitly specified using sorting operations.

By relying on row order to convey meaning, we


First Normal Form (1NF) violate the principles of 1NF. In database design,
data should be stored in a way that eliminates
First Normal Form (1NF) is the initial stage of dependencies on row order. The focus should be
on the data itself, not the position of the data
database normalization. It sets the basic
within the table.
requirements for a table to be considered well-
structured and eliminates duplicate data within a The solution is very simple. Be explicit – if we
want to capture height information, we should
single row.
devote a separate column to it – like this.

1) To understand 1NF, let's consider a scenario


where we want to store information about the
members of a band called "The Beatles."

In the given example, we have a table with a


single column storing the names of the band
members. The order of the names in each row
may vary, but they represent the same set of
members. However, relying on the order of the
rows to convey meaning violates 1NF because
row order is not meaningful in a relational
database.
Or even better, like this. So far, we’ve seen one
In the example, we have a table with a single
way in which a design can fail to achieve First
column for storing the names of the band
Normal Form.
members. Here's what the initial table might look
like:
DECIMAL, to enforce the storage of valid
numerical values only.

2) First Normal Form (1NF) emphasizes having


By maintaining defined data types within
defined data types for columns and avoiding the
columns, we promote data integrity, facilitate
mixing of different data types within the same
accurate querying and analysis, and optimize
column.
database performance. It enables the database
In a well-designed relational database, each management system to enforce constraints and
column should have a specific data type that perform operations efficiently, ensuring the
defines the kind of data it can store. For reliability and usability of the data stored in the
example, a column named "Height" might be database.
intended to store numerical values representing
3) Furthermore, every table in 1NF should have a
the height of individuals.
primary key. The primary key uniquely identifies
each row in the table. In the case of the Beatles
example, we can designate the "Beatle" column
as the primary key since each row represents a
specific Beatle. This helps maintain data integrity
by preventing duplicate entries and ensuring each
row is unique.

A primary key is a column or a combination of


columns that uniquely identifies each row in a
table. It serves as a unique identifier for the
records within the table. In 1NF, it is crucial to
have a primary key for several reasons:
The importance of maintaining consistent data Uniqueness: The primary key ensures that each
types within a column becomes apparent when row in the table is uniquely identified. It
we consider the need for data integrity and guarantees that no two rows can have the same
accurate querying. If we allow a mixture of data combination of values in the primary key
types within a column, such as storing both column(s). In our example of the Beatles, we can
numbers and strings, it can lead to several designate the "Beatle" column as the primary
problems like integrity , query analysis , and key. This means that each row represents a
performance. specific Beatle, and the primary key enforces the
To adhere to 1NF and ensure consistent data uniqueness of each Beatle's entry.
types within columns, it's crucial to assign a 4) First Normal Form (1NF) that highlights the
specific data type to each column that accurately avoidance of repeating groups or multiple values
represents the type of data it will store. In our in a single cell. In the context of a database for
example, the "Height" column should be assigned an online multiplayer game, let's consider the
a numerical data type, such as INTEGER or scenario of storing players' inventories. The goal
is to accurately represent the items each player ensure that our tables are well-organized and free
possesses. To adhere to 1NF, we need to avoid from certain problems.
storing multiple values within a single cell or
lumping all inventory data into a single row. The second normal form focuses on how the data
in a table relates to its primary key. The primary
key is a special column or a combination of
columns that uniquely identifies each row in the
table.

To understand the second normal form, let's


imagine we have two tables : a Player table and
a Player_Inventory table. In the Player table, we
store information about each player, like their
name and rating (beginner, intermediate,
advanced). In the Player_Inventory table, we
store information about the items each player has
Instead of storing the entire inventory as a single in their inventory, like the item type and
string or using multiple columns for each possible quantity.
item, the recommended approach is to create
separate rows for each item a player possesses.
Each row represents a unique combination of
player, item type, and quantity.

Here are some problems posed , that violates the


second normal form :-

Generally

SECOND NORMAL FORM (2NF) Insertion Anomaly: An insertion anomaly refers to


a situation where the database design makes it
In a database, we organize data into different difficult or impossible to insert certain data into a
tables. Each table has columns and rows to store table without also inserting redundant or
information. The second normal form helps us incomplete information. In the context of the
Player Inventory table example, an insertion
anomaly occurs when a new player, such as In database design, we organize data into tables,
"tina42," has not yet acquired any items for their and each table consists of columns (attributes)
inventory. Since the table combines both player and rows (records). The second normal form
information and inventory items, it becomes helps ensure that our table design minimizes data
impossible to insert a row for "tina42" without redundancy and maintains a clear relationship
specifying an item, resulting in the player's rating between non-key attributes and the primary key.
going unrecorded. This limitation makes it
The second normal form focuses on the
challenging to represent certain data correctly
dependencies between non-key attributes and the
during insertion
primary key of a table. The primary key is a
Deletion Anomaly: A deletion anomaly occurs unique identifier for each record in the table,
when removing data from a table unintentionally usually composed of one or more columns.
removes other related data that is still required.
In the case of the Player Inventory table example,
In the given example,Now, let's talk about the
we have two non-key attributes: Item_Quantity
deletion anomaly. Sometimes, when you want to
and Player_Rating. The primary key is a
remove a player from the list, you might
combination of the Player and Item Type
accidentally remove important information
columns.
associated with that player. For example, if a
player named "Gila" loses all their items and you To determine if the table complies with 2NF, we
delete their entry from the list, you might also analyze the dependencies of the non-key
unintentionally lose the information about Gila's attributes on the entire primary key. This means
rating. So, if you later try to find out Gila's that each non-key attribute should be functionally
rating, you won't be able to because it got dependent on the entire set of columns that make
deleted along with the player's entry. This up the primary key.
unintended loss of related data is called a
Looking at the dependency of Item_Quantity, we
deletion anomaly.
find that it satisfies the requirements of 2NF. The
Update Anomaly: An update anomaly arises when quantity of items (Item_Quantity) depends on
inconsistencies occur as a result of incomplete or both the Player and Item Type columns. For
incorrect updates to a table. In the Player every unique combination of Player and Item
Inventory table, consider the scenario where a Type, there is a specific value of Item_Quantity
player, "jdog21" improves their rating from associated with it. This dependency reflects a
"Intermediate" to "Advanced." If an update is proper relationship between the non-key attribute
executed to modify the rating, but due to an and the entire primary key.
error, only one of the two rows for "jdog21" gets
However, when examining the dependency of
updated, while the other remains unchanged. As
Player_Rating, we discover that it only depends
a result, the data becomes inconsistent, indicating
on the Player column and not the entire primary
that "jdog21" has both an "Intermediate" and an
key. Player_Rating represents the rating (e.g.,
"Advanced" rating simultaneously. This
beginner, intermediate, advanced) of a player,
inconsistency caused by an incomplete update
which remains the same for all the rows
represents an update anomaly.
associated with that player. This partial
These anomalies demonstrate the shortcomings of dependency violates 2NF because the attribute is
a table design that does not adhere to Second not functionally dependent on the entire primary
Normal Form (2NF). By ensuring that each non- key.
key attribute depends on the entire primary key,
we can avoid these anomalies and maintain the
integrity and consistency of the data in the
database.
and focuses on eliminating transitive dependencies
between non-key attributes within a table. It
ensures that the table is free from any undesired
dependencies, which helps improve data integrity
and maintain a well-structured database design.

To address this issue and achieve 2NF, we can


separate the Player attribute and its related
attributes (such as Player_Rating) into their own
table. This new table, called the Player table,
would have a primary key that uniquely identifies
each player, such as a player ID. The
Player_Rating attribute can then be directly
dependent on the primary key of the Player
table. In the given example, the Player table has been
enhanced with a new column called
By splitting the data into two tables, we Player_Skill_Level. This column represents the
eliminate the partial dependency in the Player skill level of each player in a multiplayer game.
Inventory table and ensure that each attribute in The skill levels are on a scale from 1 to 9, where
both tables is functionally dependent on the 1 represents a beginner level and 9 represents an
entire primary key of its respective table. This advanced level. Additionally, each skill level
improves data integrity and avoids anomalies corresponds to a specific player rating: "Beginner"
related to dependencies in the table design. for skill levels 1 to 3, "Intermediate" for skill
levels 4 to 6, and "Advanced" for skill levels 7 to
9.

The introduction of the Player_Skill_Level column


is intended to capture and represent the skill
progression of each player. It provides a measure
of their expertise in the game. This additional
attribute helps in understanding the players' skill
levels beyond just their ratings.

However, a problem arises when both


So generally the second normal form focuses on Player_Rating and Player_Skill_Level exist in the
the dependencies between non-key attributes and Player table. The concern is that the player's
the primary key. It ensures that non-key rating is indirectly dependent on the player's skill
attributes depend on the entire primary key, level. If a player's skill level changes, the player's
thereby reducing redundancy and maintaining a rating should also be updated accordingly to
logical relationship between data elements in a reflect their new skill level accurately.
table.
For example, if a player's skill level increases
THIRD NORMAL FORM from 3 to 4, according to the skill level to rating
mapping, their rating should be updated from
The third normal form (3NF) builds upon the "Beginner" to "Intermediate." However, if an
concepts of the first and second normal forms update is performed only on the skill level
attribute and the player rating remains improve the integrity of data in a relational
unchanged, it results in a data inconsistency. The database.
player's rating would not match their actual skill
In the context of 3NF, a table is considered to be
level, causing confusion and incorrect
in the third normal form if it satisfies the
representation of the player's abilities.
following conditions:
To address this issue and achieve the third
1. It is in second normal form (2NF).
normal form (3NF), it is necessary to remove the
2. All non-key attributes (columns) are
transitive dependency between Player_Rating and
functionally dependent on the table's
Player_Skill_Level. This can be accomplished by
primary key.
removing the Player_Rating attribute from the
3. There are no transitive dependencies
Player table. Instead, a separate table, called
between non-key attributes.
Player_Skill_Levels, can be introduced. This new
table will contain the mappings between skill Let's break down these conditions:
levels and ratings.
1. Second Normal Form (2NF): To meet the
By separating the attributes into different tables, 3NF requirements, a table must first
each attribute remains directly dependent on the comply with 2NF. This means that it
primary key (Player_ID) without any indirect should be free from partial dependencies,
dependencies. The Player table contains attributes where a non-key attribute depends on
related to the player's identification and other only a portion of the primary key. 2NF
player-specific information, while the ensures that each non-key attribute is
Player_Skill_Levels table holds the mappings fully dependent on the entire primary
between skill levels and ratings. key.

2. Functional Dependency on the Primary


Key: In a 3NF table, every non-key
attribute must depend solely on the
primary key. It should be functionally
related to the primary key and not
dependent on other non-key attributes
within the table.

3. Absence of Transitive Dependencies: A


transitive dependency occurs when a non-
key attribute depends on another non-key
attribute rather than directly on the
primary key. In 3NF, all non-key
This restructuring ensures that each attribute in a attributes should be directly dependent on
table depends solely on the key, the whole key, the primary key and not indirectly
and nothing but the key, in adherence to the through other non-key attributes.
principles of the third normal form (3NF). It Transitive dependencies are eliminated by
eliminates data inconsistencies and improves the moving the dependent attribute to a
overall integrity and structure of the database separate table.
design.

The third normal form (3NF) is a database


normalization technique that builds upon the
concepts of the first and second normal forms. It
aims to further eliminate redundancy and
By eliminating transitive dependencies and superkey, it means that there is a functional
ensuring that all non-key attributes directly dependency that is not based on the entire key,
depend on the primary key, the third normal and this violates BCNF.
form helps to reduce data redundancy, improve
To achieve BCNF, the relation needs to be
data integrity, and maintain a well-structured
decomposed into multiple smaller relations. Each
database design.
smaller relation should have its own candidate
It's important to note that achieving 3NF may not key, and every non-key attribute should be
always be necessary for every database design. functionally dependent on the entire candidate
The level of normalization required depends on key. This ensures that each relation represents a
the specific requirements and complexities of the single concept and there are no partial
data model. In some cases, achieving 3NF may be dependencies.
sufficient, while in others, higher levels of
In our example, if we identify that EmployeeID
normalization might be necessary to meet the
determines EmployeeName, Department, and
desired goals of data integrity and efficiency.
DepartmentHead (EmployeeID → EmployeeName,
Boyce-Codd Normal Form (BCNF) Department, DepartmentHead), we can decompose
the "Employees" relation into two smaller
Boyce-Codd Normal Form (BCNF) is a higher relations:
level of database normalization that deals with
1. Relation 1: EmployeeID, EmployeeName
the issue of functional dependencies within a
2. Relation 2: EmployeeID, Department,
relation. BCNF is an extension of the Third
DepartmentHead
Normal Form (3NF) and aims to eliminate certain
types of anomalies that can occur in a database. By decomposing the relation in this way, we
ensure that each relation satisfies BCNF because
BCNF is defined based on functional
every non-key attribute is fully functionally
dependencies, which are relationships between
dependent on the candidate key.
attributes in a relation. A functional dependency
states that the value of one or more attributes It's important to note that achieving BCNF is not
determines the value of another attribute. In always necessary or practical for every database
other words, knowing the values of certain design. It is typically applied in complex database
attributes allows you to determine the values of systems to address specific functional dependency
other attributes. issues and to ensure data integrity. The level of
normalization depends on the specific needs and
To understand BCNF, let's consider an example of
complexity of the data model.
a relation called "Employees" with the following
attributes: EmployeeID, EmployeeName, Fourth Normal Form
Department, and DepartmentHead.
Fourth Normal Form (4NF) is a level of database
In BCNF, the following conditions must be met: normalization that builds upon the concepts of
1. The table must be in Third Normal Form the first, second, and third normal forms. It
(3NF). addresses the issue of multi-valued dependencies,
2. For every non-trivial functional which occur when a non-key attribute is
dependency (X → Y) in the relation, X functionally dependent on part, but not all, of a
must be a superkey. candidate key.

A superkey is a set of one or more attributes that To understand 4NF, it's essential to grasp the
uniquely identifies each tuple in a relation. In concept of multi-valued dependencies (MVDs). An
other words, it is a combination of attributes that MVD exists when there is a dependency between
can be used as a primary key. If X is not a two non-key attributes such that for each value
of one attribute, there can be multiple values of
the other attribute. In other words, the two creates dependencies that can only be enforced
attributes are independent of each other. through joins. Join dependencies arise when a
non-trivial join dependency exists among the
The goal of 4NF is to eliminate or minimize these
candidate keys of a relation.
multi-valued dependencies by splitting them into
separate relations. This reduces data redundancy To understand 5NF, it's important to understand
and improves data integrity and efficiency. the concept of a join dependency. A join
dependency occurs when a relation can be
To achieve 4NF, the following conditions must be
recreated by joining two or more other relations
met:
based on their common attributes.
1. The table must be in 3NF.
The goal of 5NF is to eliminate or reduce join
2. There should be no non-key attribute that
dependencies by decomposing the relation further.
is functionally dependent on a subset of
This is achieved by splitting the original relation
the candidate key.
into multiple relations in such a way that each
3. Any multi-valued dependencies must be
relation represents a single entity or concept, and
identified and separated into new
there are no join dependencies among the
relations.
resulting relations.
By splitting the original table into separate tables,
To achieve 5NF, the following conditions must be
each containing one multi-valued dependency, the
met:
resulting relations are free from multi-valued
dependencies and redundancies. This ensures that 1. The table must be in 4NF.
each attribute is functionally dependent on the 2. There should be no non-trivial join
entire primary key and contributes to a more dependencies among the candidate keys.
robust and efficient database design. 3. Any join dependencies must be identified
and separated into new relations.
4NF is especially relevant in complex database
systems with many interrelated tables, as it helps By decomposing the relation to remove join
maintain data consistency and avoids data dependencies, the resulting relations are
anomalies associated with multi-valued independent and can be combined using natural
dependencies. joins to reconstruct the original relation.

It's important to note that achieving higher levels It's important to note that achieving 5NF is not
of normalization, such as 4NF, may not always always necessary or practical for every database
be necessary or practical for every database design. It is primarily applied in complex
design. The level of normalization depends on the database systems with a high degree of
specific requirements and complexity of the data normalization requirements and to address
model. specific join dependency issues. The level of
normalization depends on the specific needs and
Fifth Normal Form complexity of the data model.

Fifth Normal Form (5NF), also known as Project- SQL SYNTAX


Join Normal Form (PJNF), is the highest level of
database normalization. It builds upon the SQL Statements: SQL is a language used to
concepts of the previous normal forms (1NF, 2NF, interact with databases. SQL statements are used
3NF, and 4NF) and addresses the issue of join to perform various operations on the data stored
dependencies. in a database. Common SQL statements include
SELECT, INSERT, UPDATE, DELETE, ALTER,
In 5NF, the focus is on eliminating join
DROP, CREATE, USE, and SHOW. These
dependencies, which occur when the
keywords indicate the purpose of the statement.
decomposition of a relation into multiple relations
Semicolon: In SQL, statements are typically SELECT column1, column2, ..., columnN FROM
terminated with a semicolon (;). It acts as a table_name WHERE condition;
delimiter to separate multiple SQL statements
column1, column2, ..., columnN are the names of
when executing them.
the columns you want to select.
Case Sensitivity: SQL is generally case-insensitive,
table_name is the name of the table from which
meaning that keywords and commands can be
you want to retrieve data. condition is the
written in any case (uppercase, lowercase, or a
condition that the rows must satisfy to be
combination). For example, SELECT and select are
included in the result set. It is typically a logical
considered the same in SQL statements. However,
expression involving column names and
database systems like MySQL may treat table
comparison operators, such as equal to (=), not
names as case-sensitive. Therefore, when working
equal to (!=), greater than (>), less than (<),
with MySQL, it's important to use the correct
etc.
case for table names as they exist in the
database.
SQL AND/OR Clause: The AND and OR operators
SQL SELECT Statement: The SELECT statement is are used to combine multiple conditions in a
used to retrieve data from a database table. It WHERE clause. The AND operator is used to
specifies the columns that you want to retrieve specify that all conditions must be true for a row
data from and the table name from which the to be included in the result set. The OR operator
data should be retrieved. The basic syntax is as is used to specify that at least one of the
follows: conditions must be true for a row to be included.
The syntax is as follows:
SELECT column1, column2, ..., columnN
FROM table_name; SELECT column1, column2, ..., columnN FROM
table_name WHERE condition1 {AND|OR}
column1, column2, ..., columnN are the names of condition2;
the columns you want to select.
column1, column2, ..., columnN are the names of
table_name is the name of the table from which the columns you want to select.
you want to retrieve data. This statement selects
specific columns from a table and retrieves all table_name is the name of the table from which
the rows from that table. you want to retrieve data. condition1 and
condition2 are logical expressions that specify the
SQL DISTINCT Clause: The DISTINCT keyword is conditions for row selection. This statement
used to eliminate duplicate values in the result
retrieves rows that satisfy either both conditions
set. It is often used in conjunction with the
(when using AND) or at least one of the
SELECT statement. The syntax is as follows:
conditions (when using OR).
SELECT DISTINCT column1, column2, ...,
columnN FROM table_name; SQL IN Clause: The IN operator is used to specify
multiple values for a column in a WHERE clause.
It allows you to match a column's value against a
column1, column2, ..., columnN are the list of specified values. The syntax is as follows:
names of the columns you want to select without
duplicate values. SELECT column1, column2, ..., columnN FROM
table_name WHERE column_name IN (val1, val2,
table_name is the name of the table from which you ..., valN);
want to retrieve data.

SQL WHERE Clause: The WHERE clause is used column1, column2, ..., columnN are the names of
to specify conditions for retrieving data from a the columns you want to select. table_name is
table. It allows you to filter the rows based on the name of the table from which you want to
specific conditions. The syntax is as follows: retrieve data. column_name is the name of the
column you want to compare against the SQL ORDER BY Clause: The ORDER BY clause is
specified values. (val1, val2, ..., valN) is the list used to sort the result set based on one or more
of values to match against the column's value. columns in ascending (ASC) or descending (DESC)
order. It is typically used in conjunction with the
This statement retrieves rows where the column's SELECT statement. The syntax is:
value matches any of the specified values.
SELECT column1, column2, ..., columnN FROM
SQL BETWEEN Clause: The BETWEEN operator is table_name WHERE condition ORDER BY
used to select values within a range in a WHERE column_name {ASC|DESC};
clause. It allows you to specify a range of values
for a column. The syntax is as follows: This clause allows you to control the order in
which the rows are returned, making it easier to
SELECT column1, column2, ..., columnN FROM
analyze and interpret the data.
table_name WHERE column_name BETWEEN
value1 AND value2; SQL GROUP BY Clause: The GROUP BY clause is
used to group rows based on one or more
column1, column2, ..., columnN are the names of
columns and apply aggregate functions to the
the columns you want to select.
grouped data. It is often used with functions like
table_name is the name of the table from which SUM, COUNT, AVG, etc. The syntax is:
you want to retrieve data. column_name is the
SELECT aggregate_function(column_name) FROM
name of the column you want to compare against table_name WHERE condition GROUP BY
the range of values. value1 and value2 are the column_name;
starting and ending values of the range.
This clause allows you to summarize data by
grouping it based on a specific column or set of
This statement retrieves rows where the column's columns. The result set will contain one row for
value falls within the specified range. each unique combination of the grouped
column(s).
SQL LIKE Clause: The LIKE operator is used to
match patterns in a column's value using SQL COUNT Clause: The COUNT clause is used to
wildcard characters in a WHERE clause. It allows count the number of rows that satisfy a specific
you to perform pattern matching based on condition. It is commonly used in combination
specified criteria. The syntax is as follows: with the SELECT statement. The syntax is:

SELECT column1, column2, ..., columnN FROM SELECT COUNT(column_name) FROM table_name
table_name WHERE column_name LIKE { pattern WHERE condition;
};
This clause returns the count of rows that match
column1, column2, ..., columnN are the names of the given condition. It is useful for obtaining the
the columns you want to select. number of records that meet certain criteria.

table_name is the name of the table from which


you want to retrieve data. column_name is the SQL HAVING Clause: The HAVING clause is used
name of the column you want to match against in combination with the GROUP BY clause to
the specified pattern. { pattern } is the pattern filter the grouped data based on aggregate
you want to match using wildcard characters function results. It applies a condition to the
aggregated data. The syntax is:
such as % (matches any sequence of characters)
and _ (matches any single character). This
SELECT aggregate_function(column_name) FROM
statement retrieves rows where the column's value table_name WHERE condition GROUP BY
matches the specified column_name HAVING (arithmetic function
condition);
The HAVING clause allows you to specify improve the performance of database queries by
conditions on the result of aggregate functions allowing faster data retrieval. The syntax is:
(e.g., SUM, AVG) applied to grouped data. It
filters the groups based on the condition CREATE UNIQUE INDEX index_name ON
provided. table_name (column1, column2, ... columnN);

SQL CREATE TABLE Statement: The CREATE This statement creates an index with a unique
TABLE statement is used to create a new table in constraint on the specified columns of the table.
a database. It specifies the table name and
defines the columns along with their data types. SQL DROP INDEX Statement: The DROP INDEX
The PRIMARY KEY constraint can also be added statement is used to remove an existing index
to define a primary key for the table. The syntax from a table. It permanently deletes the index,
is: and the associated data will no longer be
indexed. The syntax is:
CREATE TABLE table_name (
column1 datatype, ALTER TABLE table_name
column2 datatype, DROP INDEX index_name;
column3 datatype,
... This statement allows you to remove an index
columnN datatype, that is no longer needed or is causing
PRIMARY KEY (one or more columns) performance issues.
);
SQL DESC Statement: The DESC statement is used
This statement allows you to define the structure to retrieve information about the columns and
and schema of a table, including the column their properties in a table. It provides a
names, data types, and primary key. description of the table structure, including
column names, data types, and constraints. The
SQL DROP TABLE Statement: The DROP TABLE syntax is:
statement is used to remove an entire table from
the database. It permanently deletes the table and DESC table_name;
all its associated data. The syntax is:
This statement is often used for inspecting the
DROP TABLE table_name;
structure of a table without displaying the actual
data.
This statement is useful when you no longer need
a table and want to remove it completely from SQL TRUNCATE TABLE Statement: The
the database.
TRUNCATE TABLE statement is used to remove
all rows from a table while keeping the table
SQL CREATE INDEX Statement: The CREATE
INDEX statement is used to create an index on structure intact. It is faster than the DELETE
one or more columns of a table. Indexes help statement for removing all data from a table. The
improve the performance of database queries by syntax is:
allowing faster data retrieval. The syntax is:
CREATE UNIQUE INDEX index_name ON TRUNCATE TABLE table_name;
table_name (column1, column2, ... columnN);
This statement is useful when you want to delete
This statement is useful when you no longer need all the records in a table but retain the table's
a table and want to remove it completely from structure.
the database.
SQL ALTER TABLE Statement: The ALTER TABLE
SQL CREATE INDEX Statement: The CREATE statement is used to modify an existing table
INDEX statement is used to create an index on structure. It allows you to add, drop, or modify
one or more columns of a table. Indexes help columns in a table. The syntax varies based on
the operation:
• To add a new column: ALTER TABLE This statement helps in removing specific rows or
table_name ADD column_name data_type; all rows from a table, depending on the specified
• To drop a column: ALTER TABLE conditions.
table_name DROP column_name;
SQL CREATE DATABASE Statement: The CREATE
• To modify a column: ALTER TABLE
DATABASE statement is used to create a new
table_name MODIFY column_name database in a database management system
data_type; (DBMS). The syntax is:

This statement helps in modifying the structure of


CREATE DATABASE database_name;
a table without deleting and recreating it.

SQL ALTER TABLE Statement (Rename): The This statement is used to create a new database
ALTER TABLE statement with the RENAME with the specified name.
option is used to rename an existing table to a SQL DROP DATABASE Statement: The DROP
new name. The syntax is: DATABASE statement is used to delete an existing
ALTER TABLE table_name RENAME TO database from a DBMS. The syntax is:
new_table_name;
DROP DATABASE database_name;

This statement is useful when you want to This statement permanently deletes the specified
change the name of a table. database and all its associated tables and data.

SQL INSERT INTO Statement: The INSERT INTO


SQL USE Statement: The USE statement is used to
statement is used to insert new records into a
select and start using a specific database in a DBMS.
table. It allows you to specify the columns and
The syntax is:
their corresponding values for the new row. The
USE DATABASE database_name;
syntax is

INSERT INTO table_name (column1, column2, ..., This statement sets the specified database as the
columnN) VALUES (value1, value2, ..., valueN); current active database for executing SQL
statements.
This statement helps in adding new data rows to
a table. SQL COMMIT Statement: The COMMIT statement
is used to permanently save the changes made
SQL UPDATE Statement: The UPDATE statement
within a transaction in a DBMS. The syntax is:
is used to modify existing records in a table. It
allows you to update the values of one or more COMMIT;
columns for selected rows based on specified
This statement ensures that all changes made
conditions. The syntax is:
since the start of the transaction are permanently
UPDATE table_name SET column1 = value1, saved and made visible to other users.
column2 = value2, ..., columnN = valueN
[WHERE condition]; SQL ROLLBACK Statement: The ROLLBACK
This statement helps in updating the existing data statement is used to undo or revert the changes
in a table. made within a transaction in a DBMS. The syntax
is:
SQL DELETE Statement: The DELETE statement is
used to delete one or more rows from a table ROLLBACK;
based on specified conditions. The syntax is:
This statement discards all changes made since
DELETE FROM table_name WHERE the start of the transaction, bringing the database
{CONDITION}; back to its previous state.
These SQL statements provide the ability to
delete data from tables, create and drop
databases, switch between databases, and manage
transactions. They are essential for data
manipulation, database management, and
ensuring data consistency and integrity.

You might also like