Dbms Com Notes 2080
Dbms Com Notes 2080
UNIT-1:Introduction
to DataBase System
Database Management System
1. Define the following terms with example:
i. Data iii. Database
ii. Information iv. DBMS
Ans: - The above terms are defined bellow respectively: -
Data: - Data are raw facts that can be recorded and have implicit meanings. Data helps create fact-
based information. For example: - If you have data on the grades achieved by all student, you can infer
the top performers and average grades.
Information: - Data that has been transformed into a more useful or intelligent format is known as
information.
For example: - Report card sheet.
The information is needed for the following reasons:
To gain knowledge about the surroundings.
To keep the system up to date.
To know about the rules and regulation of the society.
Database: - A database is the collection of related persistent data that contains information relevant to
an enterprise. A data is called the repository or container for a collection of data files. For example: -
A school database that maintains information about the school’s students, courses and grades.
DBMS (Database management system): - Data management includes a way to store an organize data
as well as a way to manipulate that data. The main purpose of data base management system is to
manage vast amount of data. E.g. Oracle, SQL server, MySQL and MS Access.
2. What is file system? Write down the advantage and disadvantage of file system.
Ans: - A file system is a simple way of grouping files on a hard drive or other storage media. A file system
helps you defines your files and retrieve them when you need them. Various files organized in directories
form a file system. The directory has other folders and files. Basic functions such as administration, file
naming, and granting access rules. Performed by the file system.
Grade: -10 1
Database Management System
f. Sharing: Data stored in files on computer-based system can be shared simultaneously by
multiple users.
Advantages: -
Significantly strengthened data exchange
Evolved data protection
Data integrity is maintained
Better decision-making
Data is backed up
Disadvantage: -
Hardware and software expenditures
Scale and complexity of management
Massive dimensions
Failure has a significant impact
Frequent requirements for updates
4. Explain the application of DBMS.
Ans: - Some the main applications of DBMS are given and explained below: -
a. Banking: - To store information about customers, their account number, balance, etc.
b. Airlines: - For reservations and schedule information.
Grade: -10 2
Database Management System
c. Telecommunication: - To keep records of customers call, balance left, generating monthly bills, etc.
d. Universities: - To keep records of students, courses, marks of students, etc.
e. Sales: - To keep information of customers, products list, purchase information, etc.
f. Manufacturing: - To store orders, cracking productions of items, etc.
g. Human resources: - To keep records of employee, their salary, bonus, etc.
5. Explain the types of database users.
Ans: - There are mainly 4 types of database users. They are: -
i. Naive users/parametric users: - A naive user is a user who just usage a previously created
application. For example: A customer using an ATM can simply call a program that checks
their username, password, account balance, and ultimately withdraws a certain amount from
their account.
ii. Application programmer users: - These are computer professionals who write application
programs. It builds a user interface for interacting with the database, so even beginners can
easily operate it. Application programmers use many application development tools for rapid
application development.
iii. Sophisticated users: - Experienced users never interact with databases through application
programmers. Because such users are interested and create their own queries in the database
her query language. Analysts submit queries to examine data in the database and fall into this
category.
iv. Specialized users: - Professional users are demanding users. Such users create very
sophisticated and specialized data base application. Scientist and researchers fall into this
category.
6. Explain DBMS (Database management system) architecture with figure and example.
Ans: - The design of a DBMS depends on its architecture is used to handle large number of networked pcs,
web server database server and other components.
Types of Architecture: -
Grade: -10 3
Database Management System
ii) Two Tier Architecture: - A two tier DBMS architecture is similar to the basic concept of a
client server architecture. In a two tier structure the server provides database functionality and
allows client to perform operation on the database over a direct internet connection via an API
(Application program interface). For example: ODBC (Open Database connectivity), JDBC
(Java Database Connection).
Grade: -10 4
Database Management System
Fig: - Two tier architecture
iii) Three Tier Architecture: - The Three tier DBMS architecture, the most widely used DBMS
architecture, adds another layer, called the middle tier or application tier, between the server
(database tier) and the client system (presentation tier) to handle query processing in the server,
handle the load. Reduce servers. This application, or middle tier, presents an abstract view of
the database to the end user. All user requests are handled by the application layer as there is
no direct connection between client and server.
There are four common database modules that serve different type of data and information.
a) Hierarchical Databases: - A hierarchical model represents data through a set of records, which
are organized in a hierarchical or ordered structure, and a database is a collection of such disjoint
trees.
Example: The above network model can be expressed in hierarchical model
Grade: -10 5
Database Management System
Grade: -10 6
Database Management System
d) Object-oriented database: - A combination of relational databases and object-oriented
programming makes up an object-oriented database. There are many things made with object-
oriented programming languages like C++ and Java that can be saved in relational databases, but
those things are better suited for object-oriented databases.
Example,
Consider an object that represents a bank account. The object can contain the instance
variables account number and balance. Objects can contain interest payment methods that
add interest to the balance. Unlike entities in the E-R model, each object has a unique ID.
It is irrelevant to the value it contains. Two objects with the same value are different. This
distinction is maintained at the physical layer by assigning unique object identifiers.
Although the term schema is widely used, it generally refers to three types of schema: conceptual
database schema, logical database schema, and physical database schema.
A conceptual schema provides a complete picture of what the system contains, how it is organized,
and what business rules are involved. A conceptual model is typically created as part of the process of
gathering initial project requirements.
Logical database schemas are less abstract than conceptual schemas. Uniquely defines schema objects
with information such as table names, field names, entity relationships, and constraints, all rules
governing the database. However, they usually do not contain technical requirements.
Physical database schemas provide the technical information that the logical database schema type
lacks in addition to the contextual information, such as table names, field names, entity relationships,
et cetera. That is, it also includes the syntax that will be used to create these data structures within disk
storage.
9. Difference between DBMS and file system.
Ans: - Difference between DBMS and file system are given below:-
DBMS File System
DBMS is a collection of data. In DBMS, the File system is a collection of data. In this
user is not required to write the procedures. system, the user has to write the procedures for
managing the data.
Grade: -10 7
Database Management System
DBMS gives an abstract view of data that File system provides the detail of the data
hides the details. representation and storage of data
DBMS provides a crash recovery mechanism, File system doesn't have a crash mechanism,
i.e. DBMS protects the user from the system i.e., if the system crashes while entering some
failure. data, then the content of the file will lost.
DBMS provides a good protection mechanism. It is very difficult to protect a file under the file
system.
DBMS contains a wide variety of sophisticated File system can't efficiently store and retrieve
techniques to store and retrieve the data the data.
Redundancy is control in DBMS. Redundancy not control in file system.
DBMS provide backup and recovery. Data lost in file system can't be recovered.
Grade: -10 8
Database Management System
separate entity from the
Client/ User Interface and the
data Interface.
Speed of Operation It runs at a comparatively It runs and works at a
slower pace. comparatively faster pace.
Security The two-tier DB architecture The three-tier DB architecture
allows the client to does not allow its clients and
communicate directly with the database to communicate
database- thus making it less directly- thus making it
secure. comparatively secure in the
long run.
Loss of Performance The two-tier DB architecture The three-tier DB architecture
leads to a performance loss leads to a performance loss
with an increase in the number when we happen to run a
of users. system over the Internet. Yet,
Management System that one it exhibits an overall better
can create with the MS- performance as compared to
Access, etc. its two-tier counterpart.
Examples A few examples of the two- A few examples of the three-
tier database architecture are tier database architecture are a
the Railway Reservation website on the Internet, the
System, Contact. process of designing
registration forms with
buttons, labels, text boxes, and
many more.
THE END
Grade: -10 9
Next Chapter
UNIT-2:Entity
Relationship
Mode(ER-Model)
Unit-1: Introduction to Database System
Questions.
1.Define the following terms with an example.
a.Data b.Information c.Database d. DBMS
2.What is File System ? Write down the advantages and disadvantages of of File System. (VVI)
3.What is DBMS ? Write down the advantages and disadvantages of DBMS.
4.Explain the applications of DBMS.
5.Explain the types of Database Users.
6.Explain DBMS (database) architecture with figures and examples. (VVI)
7.What is database model and describe its types.
8.Explain database Schema.
9.Differentiate between DBMS and File System.
10.Differentiate between two-tier and three -tier database architecture.
Unit-2: Entity Relationship Model(ER-Model)
Questions.
1.What do you mean by ER-Model ? Explain the different components of ER-Model.
2.Define entity and entity set .Explain the different types of entity set.
3.What is Attribute ? Explain the types of attributes in ER-Model.
4.What is keys in DBMS ? Explain the different types of keys in DBMS.
5.What do you mean by relationship ? Explain the types of relationship in dbms.
6.What is mapping cardinalities ? Explain the types of cardianlities.
concept of ER-Model
What is ER-Model
Definition :An Entity–relationship model (ER model) describes the structure of a
database with the help of a diagram, which is known as Entity Relationship Diagram (ER
Diagram).
The main components of E-R model are: entity set,Attributes and relationship set.
A simple ER Diagram:
In the following diagram we have two entities -Student and College and their
relationship.
The relationship between Student and College is many to one as a college can
have many students however a student cannot study in multiple colleges at the
same time.
Student entity has attributes such as Stu_Id, Stu_Name & Stu_Addr and
Attributes
We use a rectangle to represent an entity type in the E-R diagram, not entity.
Example- If we have two tables of Customer(Customer_id, Name, Mobile_no, Age, Gender) and
Address(Locality, Town, State, Customer_id). Here we cannot identify the address uniquely as
there can be many customers from the same locality. So, for this, we need an attribute of Strong
Entity Type i.e ‘Customer’ here to uniquely identify entities of 'Address' Entity Type.
Entity Set
Definition : Entity Set is a collection of entities of the same entity type.
We can say that entity type is a superset of the entity set as all the entities are
included in the entity type.
Let's try to understand this with the help of an example.
Example 1: In the below example, two entities E1 (2, Angel, 19, 8709054568) and E2(4,
Analisa, 21, 9847852156) form an entity set.
3.What is Attribute ? Explain the types of attributes in ER-Model.
Attribute
Types of Attributes
In ER diagram, attributes associated with an entity set may be of the following types-
1. Simple attributes
2. Composite attributes
3. Single valued attributes
4. Multi valued attributes
5. Derived attributes
6. Key attributes
1.Simple Attribute
Definition : An attribute which contains an atomic(single) value and cannot be divided further is
called a simple attribute.
Example-
2.Composite attribute:
Here, the attributes “Name” and “Address” are composite attributes as they are
composed of many other simple attributes.
3.Single Valued Attributes-
Single valued attributes are those attributes which can take only one value for a given
entity from an entity set.
Example- Here, all the attributes are single valued attributes as they can take only one specific
value for each entity.
4.Multi Valued Attributes-
Definition : Multi valued attributes are those attributes which can take more than one
value for a given entity from an entity set.
Definition : An attribute which contains more than one value for a given entity.
In an entity-relationship diagram, these attributes are represented by a double
oval shape.
Multivalued attribute
Example- Here, the attributes “Mob_no” and “Email_id” are multi valued attributes as they cantake
more than one values for a given entity.
5.Derived attribute:
Definition : An attribute which can be derived from other attribute(s) is called a derived
attribute.
For example, Age is a derived attribute as it changes over time and can be derived from another
attribute DOB (Date of birth).
Here, the attribute “Age” is a derived attribute as it can be derived from the
attribute “DOB”.
6.Key attribute:
Definition : An attribute which can uniquely identify an entity in an entity set is called a
key attribute. It represents a primary key in the ER diagram.
They allow you to find the relation between two tables. Keys help you uniquely identify a
row in a table by a combination of one or more columns in that table.
Types of Keys
Generally,There are four different types of key:
In the table defined above super key would include student_id, (student_id,
name), phone etc.
Confused? The first one is pretty simple as student_id is unique for every row of data,
hence it can be used to identity each row uniquely.Next comes, (student_id, name), now
name of two students can be same, but their student_id can't be same hence this
combination can also be a key.Similarly, phone number for every student will be unique,
hence again, phone can also be a key.So they all are super keys.
2.Candidate Key
Candidate keys are defined as the minimal set of fields which can uniquely identify each
record in a table.
It is an attribute or a set of attributes that can act as a Primary Key for a table to uniquely
identify each record in that table. There can be more than one candidate key.
In our example, student_id and phone both are candidate keys for table Student.
A candiate key can never be NULL or empty. And its value should be unique.
Properties of Candidate key:
Definition :Key that consists of two or more attributes that uniquely identify any record
in a table is called Composite key.
But the attributes which together form the Composite key are not a key independentely or
individually.
In the above picture we have a Score table which stores the marks scored by a student in
a particular subject.
In this table student_id and subject_id together will form the primary key, hence it is a
composite key.
6.Foreign Key
Definition : Foreign keys are the attributes in a table ,whose value match as primary key
in another table.
Foreign Key can contain duplicate value
Also can contain Null Value.
EMPLOYEE DEPARTMENT
Dep.No Dep.Name Dep.Loc
E.No E.Name Salary Dep.No
D1 Sales Delhi
1 Rahul 5000 D1
D2 Purchase Bangalore
2 Roshan 10000 D2
3 Hari 15000
4 Bikash 5000 D4
5. Explain different types of relationship with examples.
Ans: The logical representation among entities is called relationship. There are four different types of
relationship namely,
1. One to One
2. One to Many
3. Many to One
4. Many to Many
Example 2: one student can enroll only for one course and a course will also have only one Student.
pg. 5
Database Management System-2080
System
Example 2: Student enrolls for only one Course but a Course can have many Students
Example 2: many students can enroll for more than one courses.
Definition : Cardinality defines the number of entities in one entity set, which can be
associatedwith the number of entities of other set via relationship set.
For binary relationship set R on an entity set A and B, there are four possible
mappingcardinalities. These are as follows:
1. One-to-one − By this cardinality constraint, One entity from entity set A can be associated
with at most one entity of entity set B and vice versa.
2. One-to-many −By
By this cardinality constraint, One entity from entity set A can be associated
with more than one entities of entity set B however an entity from entity set B, can be
3. Many-to-one − By this cardinality constraint, More than one entities from entity set A can be
associated with at most one entity of entity set B, however an entity from entity set B can be
associatedwith more than one entity from entity set A.
4. Many-to-many −By this cardinality constraint, One entity from A can be associated with
more thanone entity from B and vice versa.
Assignments
1.What is functional Dependency ? Explain the different types of functional dependency .
2.Differentiate between trivial and non-trivial functional dependencies.
3.Define Normalization . Write the advantages and disadvantages of Normalization.
4.Explain the different types of normalization.
4.Differentiate between :
a.1NF and 2NF .
b.2NF an d 3NF
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
Contents
4. DataBase Design
4.1 Functional Dependencies:
Introduction,
Trivial and Non-trivial Dependencies,
Closure of a Set of Dependencies,
Closure of a Set of Attributes.
4.2 Data Normalization:
Introduction,
Decomposition and
Functional Dependencies INF, 2NF and 3NF
References
https://en.wikipedia.org/wiki/Functional_dependency
https://beginnersbook.com/2015/04/non-trivial-functional-dependency-in-dbms/
https://www.geeksforgeeks.org/functional-dependency-and-attribute-closure/
imp- https://www.minigranth.com/dbms-tutorial/closure-of-functional-
dependency/#:~:text=The%20Closure%20Of%20Functional%20Dependency,%E2%80%9
C%7BF%7D%2B%E2%80%9D.
https://www.gatevidyalay.com/functional-dependency-in-dbms/
https://www.gatevidyalay.com/closure-of-an-attribute-set/
https://www.gatevidyalay.com/database-normalization/
DBMS P a g e 1 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
DBMS P a g e 2 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
FD : A B
Here, A & B are the attributes present in any relation.
“A B” means, “B” is functionally dependent upon “A” or “A”
functionally determines “B”. Functional dependency acts as
a constraint between set of attributes present in any database.
The left side of FD is known as a determinant and the right side is
known as a dependent.
Examples
Functional Dependency in DBMS and Keys are the most important concepts that are
used as a foundation in database normalization. We will try to explain you with example
how actually functional dependency works.
DBMS P a g e 3 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
We can conclude from Roll_No attribute in the table, we are able to determine the
Name of student uniquely and same is the case with marks too. Hence, we can say that
Name and Marks are functionally dependent on Roll_No but the vice versa is not true.
FD1 : Roll_No Name
FD2 : Roll_No Marks
NOTE : In the above scenario, Two Roll_No can have same Name(i.e. Anoop in the
above table as Roll_No-1 and Roll_No-5 but two same Name cannot have same
Roll_No. This is how Functional dependency in DBMS concept works.
DBMS P a g e 4 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
Introduction
Definition : The attributes of a table are said to be dependent on each other when an
attribute of a table uniquely identifies another attribute of the same table.
Examples:
Example 1:
Example 2:
Formally:
If column A of a table uniquely identifies the column B of same table then it can represented
as A->B (Attribute B is functionally dependent on attribute A)
DBMS P a g e 5 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
Introduction
Definition : In any relation, a functional dependency α → β holds if- Two or more
tuples having same value of attribute α also have same value for attribute β.
Mathematically,
If α and β are the two sets of attributes in a relational table R where-
α⊆R
β⊆R
Then, for a functional dependency to exist from α to β,
If t1[α] = t2[α], then t1[β] = t2[β]
α β
t1[α] t1[β]
fd : α → β
t2[α] t2[β]
……. …….
Example
Table 2:
Table 1:
α β
α β a 1
a 1 b 2
b 2 a 3
a 1 c 4
c 4
DBMS P a g e 6 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
Rule-01:
A functional dependency X → Y will always hold if all the values of X are unique (different)
irrespective of the values of Y.
Example
Consider the following table:
A B C D E
5 4 3 2 2
8 5 3 2 1
1 9 3 3 5
4 7 3 3 8
The following functional dependencies will always hold since all the values of attribute ‘A’
are unique-
A→B
A → BC
A → CD
A → BCD
A → DE
A → BCDE
In general, we can say following functional dependency will always hold-
Rule-02:
A functional dependency X → Y will always hold if all the values of Y are same irrespective
of the values of X.
Example
Consider the following table-
DBMS P a g e 7 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
A B C D E
5 4 3 2 2
8 5 3 2 1
1 9 3 3 5
4 7 3 3 8
The following functional dependencies will always hold since all the values of attribute ‘C’ are
same-
A→C
AB → C
ABDE → C
DE → C
AE → C
In general, we can say following functional dependency will always hold true-
Any combination of attributes A, B, C, D, E → C
DBMS P a g e 8 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
Note : A subset is a set whose all elements are members of another set. The symbol
"⊆" means "is a subset of". The symbol "⊂" means "is a proper subset of". Since all of
the members of set A are members of set B, A is a subset of B. Symbolically this is
represented as A ⊆ B. Example : A={1,2,3,4,5} B={1,2,3} C={1,2,4} .Here B⊆A but
C⊄A
Trivial means waste or disadvantage.
Non-trivial means useful.
DBMS P a g e 9 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
Examples:
The examples of trivial functional dependencies are:
Example 1:
FD 1 : AB → A
FD 2 : AB → B
FD 3: AB → AB
Example 2:
Consider a table with two columns Student_id and Student_Name.
FD 1: {Student_Id, Student_Name} ->Student_Id is a trivial functional
dependency as Student_Id is a subset of {Student_Id, Student_Name}. That makes sense
because if we know the values of Student_Id and Student_Name then the value of Student_Id
can be uniquely determined.
Also, FD 2: Student_Id ->Student_Id &
Example 3:
Consider a table with two columns Employee_Id and Employee_Name.
FD 1: {Employee_id, Employee_Name} → Employee_Id is a trivial
functional dependency as Employee_Id is a subset of {Employee_Id, Employee_Name}.
Also, FD 2: Employee_Id → Employee_Id and
DBMS P a g e 10 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
Example 2:
An employee table with three attributes: emp_id, emp_name,
emp_address. The following functional dependencies are non-trivial:
FD 1: emp_id ->emp_name (emp_name is not a subset of emp_id)
FD 2: emp_id ->emp_address (emp_address is not a subset of emp_id)
On the other hand, the following dependencies are trivial:{emp_id, emp_name}
-> emp_name [emp_name is a subset of {emp_id, emp_name}]
Example 3:
FD 1: ID → Name
FD 2: Name → DOB
DBMS P a g e 11 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
Examples
Example-1 : Consider the table student_details having (Roll_No, Name,Marks,
Location) as the attributes and having two functional dependencies.
Now, We will calculate the closure of all the attributes present in the relation using the
three steps mentioned below.
Step-1 : Add attributes present on the LHS of the first functional dependency to the closure.
{Roll_no}+ = {Roll_No}
DBMS P a g e 12 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
Step-2 : Add attributes present on the RHS of the original functional dependency to the
closure.
Step-3 : Add the other possible attributes which can be derived using attributes present on the
RHS of the closure. So Roll_No attribute cannot functionally determine any attribute but Name
attribute can determine other attributes such as Marks and Location using 2 nd Functional
Dependency(Name Marks, Location).
Similarly, we can calculate closure for other attributes too i.e “Name”.
Step-1 : Add attributes present on the LHS of the functional dependency to the closure.
{Name}+ = {Name}
Step-2 : Add the attributes present on the RHS of the functional dependency to the closure.
Step-3 : Since, we don’t have any functional dependency where “Marks or Location” attribute
is functionally determining any other attribute , we cannot add more attributes to the closure.
Hence complete closure of Name would be :
NOTE : We don’t have any Functional dependency where marks and location can functionally
determine any attribute. Hence, for those attributes we can only add the attributes themselves
in their closures. Therefore,
{Marks}+ = {Marks}
DBMS P a g e 13 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
and
{Location}+ = { Location}
FD1 : A BC
FD2 : C B
FD3 : D E
FD4 : E D
Now, we need to calculate the closure of attributes of the relation R. The closures will be:
{A}+ = {A, B, C}
{B}+ = {B}
{C}+ = {B, C}
{D}+ = {D, E}
{E}+ = {E}
“A Candidate Key of a relation is an attribute or set of attributes that can determine the
whole relation or contains all the attributes in its closure."
FD1 : A B
FD2 : B C
{A}+ = {A, B, C}
{B}+ = {B, C}
{C}+ = {C}
DBMS P a g e 14 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
Clearly, “A” is the candidate key as, its closure contains all the attributes present in the
relation “R”.
FD1 : A BC
FD2 : C B
FD3 : D E
FD4 : E D
{A}+ = {A, B, C}
{B}+ = {B}
{C}+ = {C, B}
{D}+ = {E, D}
{E}+ = {E, D}
In this case, a single attribute is unable to determine all the attribute on its own like in
previous example. Here, we need to combine two or more attributes to determine the
candidate keys.
Hence, "AD" and "AE" are the two possible keys of the given relation “R”. Any other
combination other than these two would have acted as extraneous attributes.
NOTE : Any relation “R” can have either single or multiple candidate keys.
DBMS P a g e 15 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
Prime Attributes : Attributes which are indispensable part of candidate keys. For
example : “A, D, E” attributes are prime attributes in above example-2.
Non-Prime Attributes : Attributes other than prime attributes which does not take part
in formation of candidate keys.
Extraneous Attributes : Attributes which does not make any effect on removal from
candidate key.
FD1 : A BC
FD2 : B C
FD3 : D C
Prime Attributes : A, D.
Non-Prime Attributes : B, C
Extraneous Attributes : B, C(As if we add any of the to the candidate key, it will remain
unaffected). Those attributes, which if removed does not affect closure of that set.
A → BC
DBMS P a g e 16 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
BC → DE
D→F
CF → G
Now, let us find the closure of some attributes and attribute sets-
Closure of attribute A-
A+ = { A }
={A,B,C} ( Using A → BC )
={A,B,C,D,E} ( Using BC → DE )
={A,B,C,D,E,F} ( Using D → F )
= { A , B , C , D , E , F , G } ( Using CF → G )
Thus,
A+ = { A , B , C , D , E , F , G }
Closure of attribute D-
D+ = { D }
= { D , F } ( Using D → F )
We can not determine any other attribute using attributes D and F contained in the result set.
Thus,
D+ = { D , F }
Closure of attribute set {B, C}-
{ B , C }+ = { B , C }
={B,C,D,E} ( Using BC → DE )
={B,C,D,E,F} ( Using D → F )
= { B , C , D , E , F , G } ( Using CF → G )
Thus,
{ B , C }+ = { B , C , D , E , F , G }
Inference Rule (IR):
The Armstrong's axioms are the basic inference rule.
Armstrong's axioms are used to conclude functional dependencies on a relational
database.
The inference rule is a type of assertion. It can apply to a set of FD(functional
dependency) to derive other FD.
DBMS P a g e 17 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
Using the inference rule, we can derive additional functional dependency from the
initial set.
The Functional dependency has 6 types of inference rule:
Mathematically, If X ⊇ Y then X → Y
Example:
X = {a, b, c, d, e}
Y = {a, b, c}
Example:
In the transitive rule, if X determines Y and Y determine Z, then X must also determine
Z.
Union rule says, if X determines Y and X determines Z, then X must also determine Y
and Z.
Proof:
DBMS P a g e 18 | 19
LectureNotes Unit-4.1 :Functional Dependencies Er.Sushil Yadav
1. X → Y (given)
2. X → Z (given)
3. X → XY (using IR2 on 1 by augmentation with X. Where XX = X)
4. XY → YZ (using IR2 on 2 by augmentation with Y)
5. X → YZ (using IR3 on 3 and 4)
Decomposition rule is also known as project rule. It is the reverse of union rule.
This Rule says, if X determines Y and Z, then X determines Y and X determines Z
separately.
Proof:
1. X → YZ (given)
2. YZ → Y (using IR1 Rule)
3. X → Y (using IR3 on 1 and 2)
6. Pseudo transitive Rule (IR6)
Proof:
1. X → Y (given)
2. WY → Z (given)
3. WX → WY (using IR2 on 1 by augmenting with W)
4. WX → Z (using IR3 on 3 and 2)
DBMS P a g e 19 | 19
LectureNotes Unit-4.2 : Data Normalization Er.sushil Yadav
Contents
4. DataBase Design
4.1 Functional Dependencies:
Introduction,
Trivial and Non-trivial Dependencies,
Closure of a Set of Dependencies,
Closure of a Set of Attributes.
4.2 Data Normalization:
Introduction,
Decomposition and
Functional Dependencies INF, 2NF and 3NF
References
https://minigranth.in/dbms-tutorial/database-normalization-dbms
https://www.gatevidyalay.com/database-normalization/
DBMS P a g e 1 | 12
LectureNotes Unit-4.2 : Data Normalization Er.sushil Yadav
4.2 Normalization
Till now we are familiar with the concept of functional dependency and closure of attributes that
helps in database normalization. What does database normalization means? Let’s discuss.
Introduction
DBMS P a g e 2 | 12
LectureNotes Unit-4.2 : Data Normalization Er.sushil Yadav
Table : company_details
Here in this table Department, Dept_ID and Manager_Name are the attributes which are
same for all the employees. This type of repetition of data is called as redundancy. Let’s
see the anomalies now:
1. Insertion Anomaly :
If we want to add more employees to the above table, with insertion of every new employee
detail attributes such as Department, Dept_ID and Manager_Name will also be
inserted, which will ultimately result in higher memory usage and redundancy in data. This
is called Insertion Anomaly.
2. Deletion Anomaly :
If we want to delete details of an employee with respect to above table, all the other details
such as Department, Dept_ID and Manager_Name will also get deleted. Similarly, if we
need to delete all the other E_ID, all other details will also be deleted and the table will
become blank. This is called as Deletion Anomaly where any change in one attribute
causes the change in whole table.
3. Updation Anomaly :
If the manager of the department gets promoted and new manager comes in place of him,
then we need to update all the entries present in the table. If in case for a particular
employees the manager name is not updated, the whole data will become inconsistent. This
is called as Updation Anomaly.
DBMS P a g e 3 | 12
LectureNotes Unit-4.2 : Data Normalization Er.sushil Yadav
Yes, there is a solution to above anomalies we has discussed. Without applying any
solution to anomalies, database normalization cannot be achieved. For this, we can split or
decompose the whole Company_Details table into Employee_Details (E_ID, Name,
Dept_ID) and Department_details(Dept_ID, Dept_Name, Manager_Name).
If in case we want to update the name of manager, we will be required to update value of
just an attribute only once in the Department_Details table.
By splitting the table into two, it will enable us to remove all the anomalies which will
further result in implementation of database normalization through normal forms.
DBMS P a g e 4 | 12
LectureNotes Unit-4.2 : Data Normalization Er.sushil Yadav
Normal Description
Form
DBMS P a g e 5 | 12
LectureNotes Unit-4.2 : Data Normalization Er.sushil Yadav
Example :
However,
This relation can be brought into 1NF.
This can be done by rewriting the relation such that each cell of the table contains only
one value.
Relation is in 1NF
This relation is in First Normal Form (1NF).
NOTE
By default, every relation is in 1NF.
This is because formal definition of a relation states that value of all the attributes must be atomic.
DBMS P a g e 6 | 12
LectureNotes Unit-4.2 : Data Normalization Er.sushil Yadav
Partial Dependency
A partial dependency is a dependency where few attributes of the candidate key
determines non-prime attribute(s).
OR
A partial dependency is a dependency where a portion of the candidate key or incomplete
candidate key determines non-prime attribute(s).
In other words,
A → B is called a partial dependency if and only if-
a. A is a subset of some candidate key
b. B is a non-prime attribute.
If any one condition fails, then it will not be a partial dependency.
OR
Partial Dependency occurs when a non-prime attribute is functionally dependent on part
of a candidate key.
The 2nd Normal Form (2NF) eliminates the Partial Dependency.
NOTE-
To avoid partial dependency, incomplete candidate key must not determine any non-prime
attribute.
However, incomplete candidate key can determine prime attributes.
DBMS P a g e 7 | 12
LectureNotes Unit-4.2 : Data Normalization Er.sushil Yadav
Example
<StudentProject>
StudentID ProjectNo StudentName ProjectName
The StudentName can be determined by StudentID, which makes the relation Partial
Dependent.
The ProjectName can be determined by ProjectNo, which makes the relation Partial
Dependent.
<StudentInfo>
StudentID ProjectNo StudentName
DBMS P a g e 8 | 12
LectureNotes Unit-4.2 : Data Normalization Er.sushil Yadav
<ProjectInfo>
ProjectNo ProjectName
Example 2:
DBMS P a g e 9 | 12
LectureNotes Unit-4.2 : Data Normalization Er.sushil Yadav
A given relation is called in Third Normal Form (3NF) if and only if-
a. Relation already exists in 2NF.
b. No transitive dependency exists for non-prime attributes.
Transitive Dependency
When an indirect relationship causes functional dependency it is called Transitive
Dependency.
If P -> Q and Q -> R is true, then P-> R is a transitive dependency.
DBMS P a g e 10 | 12
LectureNotes Unit-4.2 : Data Normalization Er.sushil Yadav
NOTE-
Transitive dependency must not exist for non-prime attributes.
However, transitive dependency can exist for prime attributes.
Example:
The given relation is not in 3NF
DBMS P a g e 11 | 12
LectureNotes Unit-4.2 : Data Normalization Er.sushil Yadav
We find that in the above Student_detail relation, Stu_ID is the key and only prime key
attribute. We find that City can be identified by Stu_ID as well as Zip itself. Neither Zip is
a superkey nor is City a prime attribute. Additionally, Stu_ID → Zip→ City, so there exists
transitive dependency.
To bring this relation into third normal form, we break the relation into two relations as
follows –
DBMS P a g e 12 | 12
Unit-4:SQL
4.1:Introduction to SQL
Introduction
Definition:SQL stands for Structured Query Language used for storing and managing
data in Relational Database Management System (RDBMS).
It is a standard language for Relational Database System. It enables a user to create, read,
update and delete relational databases and tables.
SQL is the programming language for relational databases like MySQL, Oracle, Sybase,
SQL Server, Postgre, etc.
Non-relational databases (also called NoSQL) like MongoDB, DynamoDB, etc. do not
use SQL.
All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server use SQL as
their standard database language.
DBMS Page 1
Unit-4:SQL
SQL allows users to query the database in a number of ways, using English-like
statements.
Rules
SQL follows the following rules:
a. Structure query language is not case sensitive. Generally, keywords of SQL are
written in uppercase.
b. Statements of SQL are dependent on text lines. We can use a single SQL
statement on one or multiple text line.
c. Using the SQL statements, you can perform most of the actions in a database.
d. SQL depends on tuple relational calculus and relational algebra.
Characteristics of SQL
Advantages of SQL
DBMS Page 2
Unit-4:SQL
e. Interactive language:
SQL is a domain language used to communicate with the database. It is also used to
receive answers to the complex questions in seconds.
f. Multiple data view:
Using the SQL language, the users can make different views of the database structure.
SQL Datatype
SQL Datatype is used to define the values that a column can contain.
Every column is required to have a name and data type in the database table.
Datatype of SQL:
DBMS Page 3
Unit-4:SQL
1. Binary Datatypes:
There are Three types of binary Datatypes which are given below:
Data Type Description
DBMS Page 4
Unit-4:SQL
4.2:SQL Commands
SQL commands are instructions. It is used to communicate with the database. It is also
used to perform specific tasks, functions, and queries of data.
SQL can perform various tasks like create a table, add data to tables, drop the table,
modify the table, set permission for users.
Types of SQL(or SQL) Commands
There are five types of SQL commands:
DBMS Page 5
Unit-4:SQL
DBMS Page 6
Unit-4:SQL
a.CREATE:
Syntax:
Example:
b. DROP:
It is used to delete both the structure and record stored in the table.
Syntax:
Example:
C. ALTER:
It is used to alter the structure of the database. This change could be either to modify the
characteristics of an existing attribute or probably to add a new attribute.
Syntax:
To add a new column in the table
DBMS Page 7
Unit-4:SQL
Example:
d. TRUNCATE:
It is used to delete all the rows from the table and free the space containing the table.
Syntax:
Example:
DBMS Page 8
Unit-4:SQL
a. INSERT:
The INSERT statement is a SQL query. It is used to insert data into the row of a table.
Syntax:
Or
For example:
b. UPDATE:
This command is used to update or modify the value of a column in the table.
Syntax:
For example:
UPDATE students
SET User_Name = 'Sonoo'
WHERE Student_Id = '3'
DBMS Page 9
Unit-4:SQL
C.DELETE:
It is used to remove one or more row from a table.
Syntax:
For example:
DCL commands are used to grant and take back authority from any database user.
Here are some commands that come under DCL:
Grant
Revoke
Example:
Example:
DBMS Page 10
Unit-4:SQL
a.Commit:
Commit command is used to save all the transactions to the database.
Syntax:
COMMIT;
Example:
b. Rollback:
Rollback command is used to undo transactions that have not already been saved to the database.
Syntax:
ROLLBACK;
Example:
DBMS Page 11
Unit-4:SQL
Syntax:
SAVEPOINT SAVEPOINT_NAME;
SELECT expressions
FROM TABLES
WHERE conditions;
For example:
SELECT emp_name
FROM employee
WHERE age > 20;
SQL Table
SQL Table is a collection of data which is organized in terms of rows and columns. In
DBMS, the table is known as relation(Entity) and row as a tuple and column header
is called an attribute.
Table is a simple form of data storage. A table is also considered as a convenient
representation of relations.
Let's see an example of the EMPLOYEE table:
DBMS Page 12
Unit-4:SQL
Operation on Table:
1. Create table
2. Drop table
3. Delete table
4. Rename table
SQL Create Table:
SQL create table is used to create a table in the database. To define the table, you should
define the name of the table and also define its columns and column's data type.
Syntax:
Create table "table_name"
("column1" "data type",
"column2" "data type",
"column3" "data type",
...
"columnN" "data type");
Example:
DBMS Page 13
Unit-4:SQL
If you create the table successfully, you can verify the table by looking at the message by
the SQL server. Else you can use DESC command as follows:
DBMS Page 14
Unit-4:SQL
Now, we can check whether the table exists or not using the following command:
Example:
DBMS Page 15
Unit-4:SQL
Here, the expression is the field name of the table that you want to select data from.
Use the following syntax to select all the fields available in the table:
DBMS Page 16
Unit-4:SQL
Example:
EMPLOYEE
Output:
EMP_ID
1
2
3
4
5
EMP_NAME SALARY
Kristen 150000
Russell 200000
Angelina 600000
Robert 350000
Christian 260000
DBMS Page 17
Unit-4:SQL
To fetch all the fields from the EMPLOYEE table, use the following query:
DBMS Page 18
Unit-4:SQL
Syntax:
Query:
Output: After executing this query, the EMPLOYEE table will look like:
EMP_ID EMP_NAME CITY SALARY AGE
1 Angelina Chicago 200000 30
2 Robert Austin 300000 26
3 Christian Denver 100000 42
4 Kristen Washington 500000 29
5 Russell Los angels 200000 36
Query:
INSERT INTO EMPLOYEE (EMP_ID, EMP_NAME, AGE) VALUES (7, 'Jack', 40);
DBMS Page 19
Unit-4:SQL
Output: After executing this query, the table will look like:
EMP_ID EMP_NAME CITY SALARY AGE
1 Angelina Chicago 200000 30
2 Robert Austin 300000 26
3 Christian Denver 100000 42
4 Kristen Washington 500000 29
5 Russell Los angels 200000 36
Sample Table:
EMPLOYEE
EMP_ID EMP_NAME CITY SALARY AGE
1 Angelina Chicago 200000 30
2 Robert Austin 300000 26
3 Christian Denver 100000 42
4 Kristen Washington 500000 29
5 Russell Los angels 200000 36
DBMS Page 20
Unit-4:SQL
UPDATE table_name
SET column_name = value
WHERE condition;
Query:
UPDATE EMPLOYEE
SET EMP_NAME = 'Emma'
WHERE SALARY = 500000;
Output: After executing this query, the EMPLOYEE table will look like:
EMP_ID EMP_NAME CITY SALARY AGE
1 Angelina Chicago 200000 30
2 Robert Austin 300000 26
3 Christian Denver 100000 42
4 Emma Washington 500000 29
5 Russell Los angels 200000 36
DBMS Page 21
Unit-4:SQL
UPDATE table_name
SET column_name = value1, column_name2 = value2
WHERE condition;
Query:
UPDATE EMPLOYEE
SET EMP_NAME = 'Kevin', City = 'Boston'
WHERE EMP_ID = 5;
UPDATE table_name
SET column_name = value1;
Query:
DBMS Page 22
Unit-4:SQL
UPDATE EMPLOYEE
SET EMP_NAME = 'Harry';
Sample Table:
EMLOYEE
EMP_ID EMP_NAME CITY SALARY AGE
1 Angelina Chicago 200000 30
2 Robert Austin 300000 26
3 Christian Denver 100000 42
4 Kristen Washington 500000 29
5 Russell Los angels 200000 36
DBMS Page 23
Unit-4:SQL
Output: After executing this query, the EMPLOYEE table will look like:
EMP_ID EMP_NAME CITY SALARY AGE
1 Angelina Chicago 200000 30
2 Robert Austin 300000 26
3 Christian Denver 100000 42
5 Russell Los angels 200000 36
6 Marry Canada 600000 48
Deleting Multiple Record
Delete the row from the EMPLOYEE table where AGE is 30. This will delete two
rows(first and third row).
Query
Output: After executing this query, the EMPLOYEE table will look like:
EMP_ID EMP_NAME CITY SALARY AGE
2 Robert Austin 300000 26
3 Christian Denver 100000 42
5 Russell Los angels 200000 36
6 Marry Canada 600000 48
Delete all of the records
Delete all the row from the EMPLOYEE table. After this, no records left to display. The
EMPLOYEE table will become empty.
Syntax
DBMS Page 24
Unit-4:SQL
Query
Output: After executing this query, the EMPLOYEE table will look like:
EMP_ID EMP_NAME CITY SALARY AGE
Note: Using the condition in the WHERE clause, we can delete single as well as multiple
records. If you want to delete all the records from the table, then you don't need to use the
WHERE clause.
4.5:Views in SQL
Views in SQL are considered as a virtual table. A view also contains rows and columns.
To create the view, we can select the fields from one or more tables present in the
database.
A view can either have specific rows based on certain condition or all the rows of a table.
Sample table:
Student_Detail
Student_Marks
DBMS Page 25
Unit-4:SQL
A view can be created using the CREATE VIEW statement. We can create a view from
a single table or multiple tables.
Syntax:
FROM table_name
WHERE condition;
FROM Student_Details
Just like table query, we can query the view to view the data.
Output:
DBMS Page 26
Unit-4:SQL
NAME ADDRESS
Stephan Delhi
Kathrin Noida
David Ghaziabad
3.Creating View from multiple tables
View from multiple tables can be created by simply include multiple tables in the
SELECT statement.
In the given example, a view is created named MarksView from two tables
Student_Detail and Student_Marks.
Query:
4. Deleting View
A view can be deleted using the Drop View statement.
Syntax
DBMS Page 27
Unit-4:SQL
Example:
https://www.scaler.com/topics/clause-in-sql/
SQL clause helps us to retrieve a set or bundles of records from the table.
SQL clause helps us to specify a condition on the columns or the records of a table.
A clause in SQL is a built-in function that helps to fetch the required records from a
database table.
A clause receives a conditional expression, i.e. a column name or some terms involving
the columns.
The clause calculates the result based on the given statements in the expression.
When a large amount of data is stored in the database, clauses are helpful to filter and
There are various types of clauses available in SQL, and some of them are listed below:
Clause Description
HAVING HAVING clause can be used in a GROUP BY clause. It is used to specify a
search condition for a group in the database tables.
WHERE The WHERE clause in SQL is used to retrieve the specific data from the database
that specifies the conditions exactly that are given in the UPDATE, DELETE, etc.
DBMS Page 28
Unit-4:SQL
statements.
ORDER BY The ORDER BY clause in SQL is used for sorting the records of the database
tables.
GROUP BY To group the result set of the rows that have the same values in the result set from
the database tables, the GROUP BY clause is used.
TOP This clause is used when the database has many records. It is used to specify the
total number of records to be fetched or returned.
WITH WITH clause acts as a temporary view as it is available only during the execution
of SELECT, UPDATE, INSERT, DELETE, etc. statements. It is used to
simplify complex and long queries.
LIKE The SQL LIKE clause compares a value to similar values using wildcard
operators, i.e. per cent sign ( % ) and the underscore operator ( _ ).
FROM The FROM clause in SQL is used to select the database tables, which are
manipulated using the SELECT, DELETE, and UPDATE statements.
LIMIT The LIMIT clause is used when you are dealing with large databases. It is used to
specify the maximum number of rows to be retrieved from the table.
AND The AND clause is used when multiple conditions are specified in a query and
returns a dataset when all the conditions given in the AND clause meet the
requirements.
OR The OR clause is used when multiple conditions are specified in a query and
returns a dataset when one of those conditions gets satisfied.
What are the Uses of SQL Clause?
There are various uses of clauses in SQL based on the type of clause. The uses of some of the
clauses in SQL are mentioned below:
ORDER BY
To sort the database records, you can use the ORDER BY clause in SQL. This clause in
SQL is used to arrange the fetched data in ascending or descending order based on the
requirements.
WHERE
DBMS Page 29
Unit-4:SQL
The WHERE clause in SQL is used to fetch the data or certain records that match the
specified condition in the SELECT statement. SQL's WHERE clause is also used with
the DELETE, UPDATE, etc. statements.
GROUP BY
Another usage of the clause in SQL is to group the rows that have the same values in the
result set, and this can be achieved by using the GROUP BY clause in SQL.
TOP
If you want to determine the total number of record rows in the result then you can use
the TOP clause in SQL.
AND
The AND clause is used with the UPDATE and DELETE statements and returns the
resultant dataset only when all the conditions given with the AND clause are satisfied.
OR
The OR clause is also used with the UPDATE and DELETE statements and returns the
resultant dataset when one or more than one condition is satisfied.
LIMIT
When the amount of data in the database is very large, the LIMIT clause is used to
restrict the number of rows from the database records.
DBMS Page 30
Unit-4:SQL
Output:
stu_id stu_name stu_fees stu_subject stu_age stu_class
1 Divyesha Patil 3000 Maths 16 10
2 Mayra Pandit 2000 Social Science 15 10
4 Manvi Tyagi 2000 Social Science 16 9
5 Joy Yadav 3000 Maths 16 9
6 Tisha Shah 2500 Science 15 9
As shown in the output, the WHERE clause in SQL fetches the records of those students whose
fee is less than 3500.
Example: GROUP BY clause
The following query uses the GROUP BY clause to fetch the total fees in the students'
individual classes. This can be easily done by grouping of the rows from the Students table.
SELECT SUM(stu_fees), stu_class
FROM Students
GROUP BY stu_class;
DBMS Page 31
Unit-4:SQL
Output:
stu_fees stu_class
9000 10
4500 11
7500 9
As shown in the output above, the GROUP BY clause is used to group the rows of the students
based on the student class column. The total fees in an individual class are summed up, and the
grouped rows are displayed in the table.
Output:
stu_id stu_name stu_fees stu_subject stu_age stu_class
2 Mayra Pandit 2000 Social Science 16 10
4 Manvi Tyagi 2000 Social Science 16 9
6 Tisha Shah 2500 Science 15 9
1 Divyesha Patil 3000 Maths 16 10
5 Joy Yadav 3000 Maths 16 9
7 Surbhi Soni 4000 Chemistry 17 10
3 Kunal Purohit 4500 Chemistry 17 11
In the above example, the ORDER BY clause is applied to the column stu_fees to sort the final
result based on the fees of the students.
DBMS Page 32
Unit-4:SQL
FROM Students
GROUP BY stu_id
HAVING stu_age < 17;
Output:
stu_id stu_name stu_fees stu_subject stu_age stu_class
1 Divyesha Patil 3000 Maths 16 10
2 Mayra Pandit 2000 Social Science 15 9
4 Manvi Tyagi 2000 Social Science 16 9
5 Joy Yadav 3000 Maths 16 10
6 Tisha Shah 2500 Science 15 9
In the above output, you can see that the HAVING clause is used to fetch the records of students
under 17. Also, note that the GROUP BY clause is mandatory if you are using
the HAVING clause in SQL.
https://beginnersbook.com/2014/05/order-by-clause-in-sql/
DBMS Page 33
Unit-4:SQL
Query:
SELECT EMP_NAME
FROM EMPLOYEES
WHERE EMP_AGE > 23;
Result:
+----------+
| EMP_NAME |
+----------+
| Peter |
| Chaitanya|
| Rajat |
+----------+
Fetch all the details of employees having salary greater than 6000.
Query:
SELECT *
FROM EMPLOYEES
WHERE EMP_SALARY > 6000;
Result:
+------+----------+---------+----------+
|SSN | EMP_NAME | EMP_AGE |EMP_SALARY|
+------+----------+---------+----------+
| 101 | Steve | 23 | 9000.00 |
| 499 | Chaitanya| 29 | 6588.00 |
| 689 | Rajat | 24 | 8900.00 |
| 700 | Ajeet | 20 | 18300.00 |
The AND clause is used with the UPDATE and DELETE statements and returns the
resultant dataset only when all the conditions given with the AND clause are satisfied.
When multiple conditions are joined using AND operator, only those rows will be
fetched from the database which meets all the conditions
DBMS Page 35
Unit-4:SQL
Result:
+----------+
| STU_NAME |
+----------+
| Negan |
+----------+
OR Operator or OR Clause
The OR clause is also used with the UPDATE and DELETE statements and returns the
resultant dataset when one or more than one condition is satisfied
When multiple conditions are joined using OR operator, all those rows will be fetched
from the database which meet any of the given conditions.
+----+--------------+-----+-----------+----------+
| ID | EMP_NAME | AGE | ADDRESS | SALARY |
+----+--------------+-----+-----------+----------+
| 90 | David | 30 | Agra | 10000 |
| 91 | Steve | 31 | Delhi | 9000 |
| 92 | Ajeet | 29 | Gurgaon | 11000 |
| 93 | Rahul | 33 | Noida | 19000 |
| 94 | Pappu | 35 | Agra | 9900 |
+----+--------------+-----+-----------+----------+
Lets write an SQL statements to fetch the details of the employees, where either employee age is
“greater than 30” or address is “Agra”.
Query:
SELECT *
FROM EMPLOYEE
WHERE AGE > 30 OR ADDRESS = 'Agra';
DBMS Page 36
Unit-4:SQL
Result:
+----+--------------+-----+-----------+----------+
| ID | EMP_NAME | AGE | ADDRESS | SALARY |
+----+--------------+-----+-----------+----------+
| 90 | David | 30 | Agra | 10000 |
| 91 | Steve | 31 | Delhi | 9000 |
| 93 | Rahul | 33 | Noida | 19000 |
| 94 | Pappu | 35 | Delhi | 9900 |
+----+--------------+-----+-----------+----------+
Explanation:
Row number 1 is in the output because it meets the second condition (ADDRESS = ‘Agra’).
Row number 2nd and 4th are in the output because they meet the first condition (AGE > 30).
Row number 5th is in the output because it meets both the conditions.
ORDER BY clause is used to sort the returned records in an order. By using ORDER
BY clause, we can sort the result in ascending or descending order. This clause can be
ORDER BY Syntax
SELECT column_name1, column_name2, column_name3....
FROM table_name
WHERE Condition
ORDER BY column_name1, column_name2, .... (ASC OR DESC);
Here ASC is used for sorting in ascending order and DESC for descending order .
SQL ORDER BY clause example
+---------+----------+-----+-----------+----------+
| ROLL_NO | NAME | AGE | BRANCH | CITY |
+---------+----------+-----+-----------+----------+
| 10001 | Kate | 22 | CSE | Mumbai |
| 10002 | Richard | 21 | ECE | Delhi |
| 10003 | Rick | 33 | ME | Chennai |
| 10004 | Peter | 26 | CSE | Delhi |
DBMS Page 37
Unit-4:SQL
SELECT *
FROM STUDENT
ORDER BY AGE;
Note: The default order of sorting is ascending so the rows will be sorted based on the column
“AGE”, even though we have not used the ASC keyword in order by clause. So it is safe to say
that the following query is same as the above query and would fetch the same result.
SELECT *
FROM STUDENT
ORDER BY AGE ASC;
Result:
+---------+----------+-----+-----------+----------+
| ROLL_NO | NAME | AGE | BRANCH | CITY |
+---------+----------+-----+-----------+----------+
| 10002 | Richard | 21 | ECE | Delhi |
| 10001 | Kate | 22 | CSE | Mumbai |
| 10005 | Steve | 22 | CSE | Noida |
| 10006 | Mark | 22 | ECE | Jaipur |
| 10007 | Brad | 23 | ME | Rampur |
| 10004 | Peter | 26 | CSE | Delhi |
| 10003 | Rick | 33 | ME | Chennai |
+---------+----------+-----+-----------+----------+
SQL ORDER BY DESC example
Table: STUDENT
+---------+----------+-----+-----------+----------+
| ROLL_NO | NAME | AGE | BRANCH | CITY |
+---------+----------+-----+-----------+----------+
| 10001 | Kate | 22 | CSE | Mumbai |
| 10002 | Richard | 21 | ECE | Delhi |
| 10003 | Rick | 33 | ME | Chennai |
| 10004 | Peter | 26 | CSE | Delhi |
| 10005 | Steve | 22 | CSE | Noida |
| 10006 | Mark | 22 | ECE | Jaipur |
| 10007 | Brad | 23 | ME | Rampur |
+---------+----------+-----+-----------+----------+
DBMS Page 38
Unit-4:SQL
The following SQL statement will fetch the student names from the table “STUDENT” and the
returned names will be sorted in descending order (we have used DESC for descending order in
the ORDER BY clause).
SELECT NAME
FROM STUDENT
ORDER BY NAME DESC;
Result:
+----------+
| NAME |
+----------+
| Steve |
| Rick |
| Richard |
| Peter |
| Mark |
| Kate |
| Brad |
+----------+
As you can see, we have got a list of student names sorted in the descending order.
DBMS Page 39
Unit-4:SQL
4.4:SQL JOIN
https://www.studytonight.com/dbms/joining-in-sql.php
As the name shows, JOIN means to combine something. In case of SQL, JOIN means "to
combine two or more tables".
SQL Join is an operation in DBMS(DataBase Management System) that combines the
row of two or more tables based on related(matching) columns between them.
SQL Join is used to fetch data from two or more tables, which is joined to appear as
single set of data. It is used for combining column from two or more tables by using
values common to both tables.
JOIN Keyword is used in SQL queries for joining two or more tables.
Types of SQL JOIN
Different types of Joins are as follows:
1. INNER JOIN
2. NATURAL JOIN
3. OUTER JOIN
a. LEFT OUTER JOIN
b. RIGHT OUTER JOIN
c. FULL OUTER JOIN
1.INNER Join or EQUI Join
This is a simple JOIN in which the result is based on matched data as per the equality
condition specified in the SQL query.
Inner Join Syntax is,
SELECT column-name-list FROM
table-name1 INNER JOIN table-name2
WHERE table-name1.column-name = table-name2.column-name;
Diagram
DBMS Page 40
Unit-4:SQL
ID Address
1 DELHI
2 MUMBAI
3 CHENNAI
1 abhi 1 DELHI
2 adam 2 MUMBAI
3 alex 3 CHENNAI
2.Natural JOIN
Natural Join is a type of Inner join which is based on column having same name and
same datatype present in both the tables to be joined.
DBMS Page 41
Unit-4:SQL
1 abhi DELHI
2 adam MUMBAI
3 alex CHENNAI
In the above example, both the tables being joined have ID column(same name and same
datatype), hence the records for which value of ID matches in both the tables will be the result of
Natural Join of these two tables.
DBMS Page 42
Unit-4:SQL
3.OUTER JOIN
Outer Join is based on both matched and unmatched data. Outer Joins subdivide further into,
a. Left Outer Join
b. Right Outer Join
c. Full Outer Join
a.LEFT Outer Join
The left outer join returns a result set table with the matched data from the two tables and
then the remaining rows of the left table and null from the right table's columns.
Syntax for Left Outer Join is,
Diagram
DBMS Page 43
Unit-4:SQL
ID Address
1 DELHI
2 MUMBAI
3 CHENNAI
7 NOIDA
8 PANIPAT
ID NAME ID Address
1 abhi 1 DELHI
2 adam 2 MUMBAI
3 alex 3 CHENNAI
4 anu null null
5 ashish null null
b.RIGHT Outer Join
The right outer join returns a resultset table with the matched data from the two tables
being joined, then the remaining rows of the right table and null for the
remaining left table's columns.
Syntax for Right Outer Join is,
SELECT column-name-list FROM
table-name1 RIGHT OUTER JOIN table-name2
ON table-name1.column-name = table-name2.column
DBMS Page 44
Unit-4:SQL
Diagram
1 abhi
2 adam
3 alex
4 anu
5 ashish
ID Address
1 DELHI
2 MUMBAI
3 CHENNAI
7 NOIDA
8 PANIPAT
DBMS Page 45
Unit-4:SQL
1 abhi 1 DELHI
2 adam 2 MUMBAI
3 alex 3 CHENNAI
Diagram
DBMS Page 46
Unit-4:SQL
ID NAME
1 abhi
2 adam
3 alex
4 anu
5 ashish
and the class_info table,
ID Address
1 DELHI
2 MUMBAI
3 CHENNAI
7 NOIDA
8 PANIPAT
Full Outer Join query will be like,
DBMS Page 47
Unit-4:SQL
Assignment
1.Define SQL .Write the characteristics of SQL.
2.List and explain different types of SQL or SQL commands .(VVI)
3.List and explain different types of SQL Join . .(VVI)
4.Explain SQL View.
5.Explain SQL Clause.
DBMS Page 48
Unit-6:DataBase Transaction
6.1:Introduction to Transaction
6.2:Concurrency in Transaction
6.3:ACID properties
6.4:State of Transaction
6.1:Introduction to Transaction
Introduction
The transaction is a set of logically related operation. It contains a group of tasks.
A transaction is an action or series of actions. It is performed by a single user to perform operations
for accessing the contents of the database.
Set of operation or group of task is called Transaction.
Example:Deposit Money,Withdraw Money,Transfer Money,Balance enquiry,print statement,Ticket
Booking,etc.
The transaction is a process in which
1.Input is chosen
2.Desired operations are performed on it.
3.Output is generated.
fig:Database Transaction
Example: Suppose an employee of bank transfers Rs 800 from X's account to Y's account. This
small transaction contains several low-level tasks:
X's Account
1. Open_Account(X)
2. Old_Balance = X.balance
3. New_Balance = Old_Balance - 800
4. X.balance = New_Balance
5. Close_Account(X)
Y's Account
1. Open_Account(Y)
2. Old_Balance = Y.balance
3. New_Balance = Old_Balance + 800
4. Y.balance = New_Balance
5. Close_Account(Y)
Note: A data buffer (or just buffer) is a region of a memory used to store data temporarily while it is
being moved from one place to another.
Operations of Transaction:
Following are the main operations of transaction:
a. Read(X): Read operation is used to read the value of X from the database and stores it in a buffer in
main memory.
b. Write(X): Write operation is used to write the value back to the database from the buffer.
Let's take an example to debit transaction from an account which consists of following operations:
1. R(X);
2. X = X - 500;
3. W(X);
Let's assume the value of X before starting of the transaction is 4000.
a. The first operation reads X's value from database and stores it in a buffer.
b. The second operation will decrease the value of X by 500. So buffer will contain 3500.
c. The third operation will write the buffer's value to the database. So X's final value will be 3500.
But it may be possible that because of the failure of hardware, software or power, etc. that transaction may
fail before finished all the operations in the set.
For example: If in the above transaction, the debit transaction fails after executing operation 2 then
X's value will remain 4000 in the database which is not acceptable by the bank.
To solve this problem, we have two important operations:
1.Commit: It is used to save the work done permanently.
2. Rollback: It is used to undo the work done
6.2:Concurrency in Transaction
concurrency -occurrring or operating system at the same time
6.3:ACID properties
A transaction is a very small unit of a program and it may contain several low level tasks. A
solation, and Durability −
transaction in a database system must maintain Atomicity, Consistency, Isolation,
commonly known as ACID properties − in order to ensure accuracy, completeness, and data
integrity.
Property of Transaction
1. Atomicity
2. Consistency
3. Isolation
4. Durability
1.Atomicity
This property states that a transaction must be treated as an atomic unit, that is, either all of its
operations are executed or none.
There must be no state in a database where a transaction is left partially completed.
States should be defined either before the execution of the transaction or after the
execution/abortion/failure of the transaction.
Atomicity involves the following two operations:
a.Abort: If a transaction aborts then all the changes made are not visible.
b.Commit: If a transaction commits then all the changes made are visible.
2.Consistency
The database must remain in a consistent state after any transaction. No transaction should
have any adverse effect on the data residing in the database. If the database was in a
consistent state before the execution of a transaction, it must remain consistent after the
execution of the transaction as well.
For example: The total amount must be maintained before or after the transaction.
The database should be durable enough to hold all its latest updates even if the system fails or
restarts.
The durability property is used to indicate the performance of the database's consistent state. It states
that the transaction made the permanent changes.
They cannot be lost by the erroneous operation of a faulty transaction or by the system failure. When
a transaction is completed, then the datab
database
ase reaches a state known as the consistent state. That
consistent state cannot be lost, even in the event of a system's failure.
The recovery subsystem of the DBMS has the responsibility of Durability property.
4.Isolation
It shows that the data which is used at the time of execution of a transaction cannot be used by the
second transaction until the first one is completed.
In isolation, if the transaction T1 is being executed and using the data item X, then that data item
can't be accessed by any other transaction
ransaction T2 until the transaction T1 ends.
The concurrency control subsystem of the DBMS enforced the isolation property.
6.4:State of Transaction
In a database, the transaction can be in one of the following states -
Active State
The active state is the first state of every transaction. In this state, the transaction is being executed.
For example: Insertion or deletion or updating a record is done here. But all the records are still not
saved to the database.
Partially committed
In the partially committed state, a transaction executes its final operation, but the data is still not
saved to the database.
In the total mark calculation example, a final display of the total marks step is executed in this state.
Committed
A transaction is said to be in a committed state if it executes all its operations successfully. In this
state, all the effects are now permanently saved on the database system.
Failed state
If any of the checks made by the database recovery system fails, then the transaction is said to be in
the failed state.
In the example of total mark calculation, if the database is not able to fire a query to fetch the marks,
then the transaction will fail to execute.
Aborted
If any of the checks fail and the transaction has reached a failed state then the database recovery
system will make sure that the database is in its previous consistent state. If not then it will abort or
roll back the transaction to bring the database into a consistent state.
If the transaction fails in the middle of the transaction then before executing the transaction, all the
executed transactions are rolled back to its consistent state.
After aborting the transaction, the database recovery module will select one of the two operations:
a.Re-start the transaction
b. Kill the transaction
Assignments
1.Define Transaction.Explain the operations of DatatBaseTransaction.
2.What do you mean by ACID Properties.Explain the ACID properties of Transaction. (VVI)
3.Explain the state of Transaction. (VVI)
4.Explain Concurrency in Transaction.
DBMS-2080 Page 1
Unit-7: Database Backup , Recovery & Security
By regularly backing up your data, you can ensure that even if your system is compromised or
suffers a hardware failure, you won’t lose any critical information. This can be especially
important for businesses that deal with sensitive customer information or financial records.
Additionally, many backup solutions offer encryption options that help keep your data safe
from prying eyes. What this means is that no one else can access your data when it’s backed
up to the cloud, for instance, unless they have the appropriate credentials to access it.
The industry standard for cloud backup encryption is 256-bit.
2.Versatility
One of the biggest advantages of data backup is its versatility. With a good backup system, you
can store any kind of data without worrying about losing it.
A versatile data backup system allows you to store all kinds of files such as documents, pictures,
videos, and audio files in one place. This means that you no longer have to worry about
managing different types of storage devices or services for your various file formats.
Whether you are an individual who needs to keep important documents safe or a business that
needs to store large amounts of customer data securely, a versatile backup system can help.
Versatility can also come in various platforms. As I’ve mentioned before, your source for data
backup could be via the cloud, like Google Drive, Dropbox, or Carbonite. It can also be local to
your internal network either with a server, or a NAS (Network Attached Storage). And if you
truly want to keep things local, your data backup could be as simple as an external hard drive.
Many external hard drives come with backup software loaded on them, so it’s not a bad place to
start.
3.Reliability
Once you have decided what platform you’re going to use to back up your data, once it’s in place
and consistently backing up your data, you know you can rely on it to restore your data if need
be.
Data loss prevention is one of the most significant advantages of backing up your files.
Prevention is always better than cure, is what I always say, and that applies to data backup.
In this digital age, losing important information due to hardware failure or cyber-attacks can have
devastating consequences for businesses. However, with a reliable data backup system, you
never have to worry about losing your valuable data, regardless of what may occur.
If anything happens to your primary storage devices, you can easily restore all your files from
your backups without any hassle. Moreover, another benefit of backing up your files is that it
enables you to recover lost or deleted data quickly and easily.
DBMS-2080 Page 2
Unit-7: Database Backup , Recovery & Security
This is one of the easiest and most convenient backup systems to set in place. Cloud storage falls under the
SaaS (Software as a Service) category, and it’s the method by which your data to stored on a remote server,
owned by a third party. This remote server is what’s referred to as “the cloud”.
The advantage of using cloud storage is that it offers unlimited space and convenient access from any device
with an internet connection. This makes cloud storage a very attractive method for data backup. And there
are many vendors(seller) to choose from. Others that you can choose from for both individual and business
usage are:
Microsoft OneDrive
Google Drive
Dropbox
Amazon Web Services
Carbonite
Acronis True Image
Idrive
There are many more to choose from of course, but these options are a great place to start.
DBMS-2080 Page 3
Unit-7: Database Backup , Recovery & Security
Using external hard drives as a backup resource is as basic as you can get. Many people start
here because it’s the most economical way of getting started with data backup and it’s the most
simple. All you need is to purchase an external with a large enough storage size.
As I mentioned before, many external hard drives come with backup software installed to help
you automatically do your backups, daily and weekly.
The main drawback of an external backup is that you are limited to that device. So if that hard
drive gets lost or stolen, so does your data. Security is very limited in this area unless you decide
to be proactive and store your external hard drive in a secured location.
This is a great place to start your backup system, but I recommend upgrading to a more secure
and advanced backup system, as business improves for you.
3.NAS (Network Attached Storage)
One popular option for backing up data is Network Attached Storage (NAS), which provides a
centralized and secure location for storing and accessing files.
There are several options to choose from when it comes to NAS devices.
NAS refers to a type of storage device that connects to your network and allows multiple
devices to access its contents. The device acts as a central location where you can store and
DBMS-2080 Page 4
Unit-7: Database Backup , Recovery & Security
share files, making it an ideal solution for backing up your data. Many NAS devices also allow
for some cloud features, where your data gets stored in the cloud using the manufacturer’s cloud
platform.
Unlike traditional external hard drives or USBs, which are limited by their capacity and
portability, NAS provides ample (Sufficient) storage space with added flexibility.
Another advantage of using NAS as your backup method is its ability to automate backups.
Sure you can do this with an external hard drive, as I’ve mentioned before. But a NAS device is
more centralized and accessible by several other devices from that network.
When selecting a NAS backup method, there are several factors to consider.
First, you must choose the right hardware that suits your needs. This includes things like storage
capacity, connectivity options, and speed.
Another key consideration when selecting a NAS backup method is security. You want to ensure
that your data is protected from unauthorized access or theft at all times.
Here are some top NAS brands for you to choose from:
Buffalo TeraStation
Western Digital My Cloud
Synology NAS Diskstation
Likewise, cloud entry level with a small amount of data is inexpensive, while large quantities of data
can steadily increase costs.
What Are the Main Disadvantages of Backing Up Data Locally?
If hackers and cybercriminals can access your live operational files, they may also try to corrupt your
database backups.It’s much safer to back up in the cloud or some other remote location than on-premises.
The drawbacks of a local backup are:
Higher costs compared to cloud backup
Scalability concerns
Increased maintenance
Enhanced cybersecurity issues
More vulnerable to events like fires and floods
DBMS-2080 Page 6
Unit-7: Database Backup , Recovery & Security
03. In simple backup is the replication of data. In simple recovery is the process to store the
database.
04. The prior goal of backup is just to keep one The prior goal of recovery is retrieve original
extra copy to refer in case of original data data in case of original data failure.
loss.
05. It helps in improving data protection. It helps in improving the reliability of the
database.
06. Backup makes the recovery process more Recovery has no role in data backup.
easier.
07. The cost of backup is affordable. The cost of recovery is expensive.
08. It’s production usage is very common. It’s production usage is very rare.
09. Example of Backup can be SnapManager Example of Recover can be SnapManager
makes a backup of everything in database. recovers the data to the last transaction.
10. Backup is not created automatically. There is automatic generation of restore points
by your computer.
11. A backup stores copies of the files in a A restore is carried out internally on your
location that is external to it. computer.
12. Backup requires extra storage space. Restore is internal so it does not require extra
external storage space.
13. Backup offers a means of recovery. Recovery aims to guarantee the atomicity of the
transaction and data.
1.Physical Backup:
Physical database backups are backups of physical files that are used to store and recover databases.
These include different data files, control files, archived redo logs, and many more. Typically, physical
backup data is kept in the cloud, offline storage, magnetic tape, or on a disc.
DBMS-2080 Page 7
Unit-7: Database Backup , Recovery & Security
Advantages:
a. This is useful when the user needs to restore the complete database to the last time.
b. It was more complex and provides granular recovery capabilities.
Disadvantages:
a. Critical for recovery of special components.
b. less secure compared to physical backup.
c. It only provides structural details.
Physical Backup Vs Logical Backup:
Physical Backup Logical Backup
Physical database backups are backups of Logical database backups are backups of logical
physical files that are used to store and files that are retrieved from the database.
recover databases.
It contains data files, control files, and archived It contains a view, a procedure, a function, and a
redo logs. table.
It copies data files when data is running or Using the EXPORT keyword Logical backup is
DBMS-2080 Page 8
Unit-7: Database Backup , Recovery & Security
stopped. done
A user needs to restore the complete database in a This is useful when users want to restore or
short period of time. transfer a copy of the database to a different
location.
More secure than logical backup. Less secure as compared to Physical backup.
Transaction Failure:
If a transaction is not able to execute or it comes to a point from where the transaction becomes
incapable of executing further then it is termed as a failure in a transaction.
Reason for a transaction failure in DBMS:
DBMS-2080 Page 9
Unit-7: Database Backup , Recovery & Security
1. Logical error: A logical error occurs if a transaction is unable to execute because of some
mistakes in the code or due to the presence of some internal faults.
2. System error: Where the termination of an active transaction is done by the database system
itself due to some system issue or because the database management system is unable to proceed
with the transaction. For example– The system ends an operating transaction if it reaches a
deadlock condition or if there is an unavailability of resources.
System Crash:
A system crash usually occurs when there is some sort of hardware or software breakdown. Some
other problems which are external to the system and cause the system to abruptly stop or
eventually crash include failure of the transaction, operating system errors, power cuts, main
memory crash, etc.
These types of failures are often termed soft failures and are responsible for the data losses in the
volatile memory. It is assumed that a system crash does not have any effect on the data stored in
the non-volatile storage and this is known as the fail-stop assumption.
Data-transfer Failure:
When a disk failure occurs amid data-transfer operation resulting in loss of content from disk
storage then such failures are categorized as data-transfer failures. Some other reason for disk
failures includes disk head crash, disk unreachability, formation of bad sectors, read-write errors
on the disk, etc.
DBMS-2080 Page 10
Unit-7:
7: Database Backup , Recovery & Security
DBMS-2080 Page 11
Unit-7: Database Backup , Recovery & Security
configuration files from one location to another. Since it makes a copy of everything, it’s a time
consuming process.
With a full backup, all data is backed up to a target drive or disk with each backup. This means that
all documents and files are stored in one file, which makes working with the backups and managing
them simple.
Pros:
Creating such a backup is quicker than a differential or incremental backup.
Managing them is easier as only one file needs to be restored.
Cons:
A regular full backup requires much more space than a differential or incremental backup.
DBMS-2080 Page 12
Unit-7: Database Backup , Recovery & Security
https://www.w3schools.in/dbms/database-security
https://phoenixnap.com/kb/database-security
https://www.javatpoint.com/database-security
https://intellipaat.com/blog/database-security/
DBMS-2080 Page 13
Unit-7: Database Backup , Recovery & Security
Numerous techniques are employed to safeguard databases against diverse threats, such as the
following:
Or
Here are the data security best practices that will help you to know how to secure your database:
Moreover, it is advisable to use two-factor authentication to add an extra layer of security. Two-
factor authentication necessitates users to present two types of identification, such as a password
combined with either a security token or biometric authentication. This reduces the risk of
unauthorized access to databases, even if the password is compromised.
2.Limit Access
Limiting access to databases is an effective way to prevent unauthorized access to sensitive data. Not
all employees or users require access to all the data stored in the database. It is important to restrict
access based on the principle of least privilege, which means granting only the minimum access
required to perform a particular task. For example, if an employee requires access to customer data,
they should only have access to that section of the database.
DBMS-2080 Page 14
Unit-7: Database Backup , Recovery & Security
Monitoring and tracking user activity within the database is crucial to promptly identifying and
reporting unauthorized access or suspicious behavior. By diligently monitoring and auditing user
activity, potential security gaps or vulnerabilities within the database can be detected, allowing for
timely remediation and fortification of the system.
3.Update and Patch Regularly
Keeping the database software up-to-date is crucial to preventing any potential security
vulnerabilities. Regular updates and patches ensure that any known security vulnerabilities are fixed.
It shows that the database is protected against potential threats. Failure to apply updates and patches
can result in security breaches that compromise sensitive data.
Maintaining a backup of the database is vital to guaranteeing the ability to restore data in the event of
data loss or corruption. It is essential to schedule regular backups and securely store them in a
protected location to prevent unauthorized access and ensure data integrity.
4.Monitor for Anomalies
Detecting and preventing potential security threats can be effectively achieved through the monitoring
of database anomalies. Anomaly detection entails the continuous observation of database activities to
identify any unusual or abnormal behavior that deviates from the expected norms. For instance, a
sudden surge in database traffic or an unauthorized attempt to access restricted data can be flagged as
anomalous activity. This will trigger appropriate actions for investigation and mitigation.
There is a wide range of tools accessible for monitoring and identifying irregularities in
databases.These tools include intrusion detection systems, network traffic analyzers, and log analysis
tools. These tools play a crucial role in recognizing potential data security risks and implementing
suitable measures
5.Data Encryption:
Data encryption is a technique used to protect data stored in a database from unauthorized access by
encrypting it using encryption algorithms. Encryption ensures that even if an unauthorized individual
gains access to the data, they cannot read or use it.
Data encryption is important as it ensures that sensitive data is protected even if it falls into the
wrong hands. Encryption also helps prevent data breaches and unauthorized access to the database.
DBMS-2080 Page 15
Unit-7: Database Backup , Recovery & Security
6.PhysicalSecurity:
Physical security safeguards the database against unauthorized access or theft through tangible
means. Measures such as securing the server room, implementing access controls for the data center,
and employing security cameras and alarms are integral components of physical security.
The significance of physical security lies in its ability to safeguard the database hardware from
physical harm or theft, ensuring its integrity and availability. Additionally, physical security plays a
vital role in preventing unauthorized individuals from gaining access to the database servers or
storage devices, thereby fortifying overall data security.
7.Network Security:
Network security pertains to safeguarding the database against unauthorized network access.
Network security measures include using firewalls, intrusion detection systems, and encryption.
Network security is important as it ensures that data is transmitted securely over the network.
Unauthorized individuals cannot intercept or modify the data in transit. Network security also helps
protect the database from external attacks such as hacking and malware.
9. Un-patched RDBMS
10. Unencrypted data
Infected software.
An endpoint device connected to the database's network.
Drive-by downloads.
Trojans hidden within email attachments.
Unauthorized on-site access to the database server.
Malware causes damage to the database in different ways. Malicious programs enable hackers to perform
one (or several) of the following actions:
Steal sensitive data.
Destroy or modify files (e.g., a ransomware attack that encrypts all files within the database).
Disrupt associated systems by crashing the database server.
Create backdoors in the database.
Gain remote access.
Spy on data or keyboard inputs.
Human Error
Here are a few mistakes that that has been done by human :
DMS Vulnerabilities
Criminals continually search for vulnerabilities in database management software (DMS). While companies
behind both commercial and open-source database platforms release patches regularly, many users fail to
install updates quickly enough to stop hackers from exploiting flaws.
There's also the danger of so-called zero-day attacks. These incidents occur when hackers discover an
exploitable vulnerability in the DMS before the database vendor has a chance to patch the issue.
Password Attacks
Most databases use passwords as the main method of user authentication. Criminals often use bots to
attempt to guess passwords, an approach that has several strategies:
Some criminals prefer stealing passwords instead of guessing them. Phishing, a form of social engineering,
is the go-to technique for stealing credentials. Phishing attackers typically try to trick employees into typing
in usernames and passwords in a fake login form.
A Denial of Service (DoS) occurs when an attacker overwhelms the database server with fake requests. The
server then becomes unable to fulfill legitimate requests, causing the device to crash or become unstable.
A more challenging form of DoS is the distributed denial of service (DDoS) attack. In a DDoS, the fake
traffic arrives from multiple servers (often malware-infected devices from unsuspecting users), making it
significantly more difficult for the security team to stop the attack.
DBMS-2080 Page 18
Unit-7: Database Backup , Recovery & Security
7.5:Concept of Recovery
Introduction
Data recovery is the process of restoring lost, corrupted, accidentally deleted, or otherwise
inaccessible data to its server, computer, mobile device, or storage device.
Database recovery is the process of restoring the database to a correct (consistent) state in the
event of a failure.
Types of Recovery Techniques in DBMS
Database recovery techniques are used in database management systems (DBMS) to restore a
database to a consistent state after a failure or error has occurred. The main goal of recovery
techniques is to ensure data integrity and consistency and prevent data loss.
There are mainly two types of recovery techniques used in DBMS
1. Rollback/Undo Recovery Technique
2. Commit/Redo Recovery Technique
1.Rollback/Undo Recovery Technique
The rollback/undo recovery technique is based on the principle of backing out or undoing the
effects of a transaction that has not been completed successfully due to a system failure or error.
This technique is accomplished by undoing the changes made by the transaction using the log
records stored in the transaction log.
The transaction log contains a record of all the transactions that have been performed on the
database. The system uses the log records to undo the changes made by the failed transaction and
restore the database to its previous state.
DBMS-2080 Page 19
Unit-7: Database Backup , Recovery & Security
Assignment
1.Define backup.Write the advantages and disadvantages of backup.Differentiate between backup and
recovery.
3.List and explain the different the different types of Database Backup . Differentiate between physical
and logical backup. (VVI)
4.List and explain the reasons for Database Failure.
5.List and Explain the different methods of Database backup. (VVI)
6.Define Database Security.Explain,How can you secure the database from threats.
Or
Explain Database Security Techniques.
7.What is Threat ? List and explain the some common threats in database. (VVI)
8.Define database recovery .Explain database recovery technique
DBMS-2080 Page 20