DBMS Unit 2
DBMS Unit 2
ENGINEERING
1. To have good understanding of database system concepts and design databases for
different applications.
2. To learn how to use a DBMS and RDBMS.
3. To implement and understand different types of DDL, DML and DCL statements.
4. To understand transaction concepts related to databases and recovery/backup
techniques required for the proper storage of data.
▪ Functional Dependency
▪ Partial Dependency
▪ Fully Functional Dependency
▪ Multivalued dependency
▪ Transitive dependency
Types of Dependencies
• Partial Dependency
• Full Dependency
• Transitive Dependency
A Partial Dependency occurs when a non-prime attribute (an attribute that is
not part of any candidate key) depends on part of a composite primary key
rather than the whole key.
OrderID, ProductID, ProductName, Quantity
OrderID and ProductID together form the composite primary key.
ProductName depends only on ProductID (not on the whole composite key).
This is a Partial Dependency because ProductName is determined by a part of
the composite key (ProductID), not the entire key.
Example
Let's take an example, we have a table where we have
columns of student roll number, name, city where student live,
and zip-code of city .
where R1 , R2, ... , Rn are the relations and ⨝ represents the natural join
operator.
Also,
– any relation that is in BCNF, is in 3NF;
– any relation in 3NF is in 2NF; and
– any relation in 2NF is in 1NF.
12/20/2024 Dr. Gitanjali , Asst. Prof., UIE-CSE, Chandigarh University
WHY WE NEED NORMALIZATION?
Normalization is the aim of well design Relational Database Management
System (RDBMS). It is step by step set of rules by which data is put in its
simplest forms. We normalize the relational database management
system because of the following reasons:
❖ You must have single value in a single column, null value can be
present.
In the above relation, AB is the only candidate key and there is no partial
dependency, i.e., any proper subset of AB doesn’t determine any non-prime
attribute.
• 2NF (and 3NF) both involve the concepts of key and non-key
attributes.
In other words,
A relation that is in First and Second Third Normal Form
Normal Form and in which no non-primary-
key attribute is transitively dependent on the
primary key, then it is in Third Normal Form
(3NF).
Definition
• Transitive functional dependency – if there a set of atribute
Z that are neither a primary or candidate key and both X –> Z
and Y –> Z holds.
Now all non-key attributes are fully functional dependent only on the primary
key. In [TABLE_BOOK], both [Genre ID] and [Price] are only dependent on
[Book ID]. In [TABLE_GENRE], [Genre Type] is only dependent on [Genre ID].
FD set:
{STUD_NO -> STUD_NAME, STUD_NO -> STUD_STATE, STUD_STATE -
> STUD_COUNTRY, STUD_NO -> STUD_AGE}
Candidate Key:
{STUD_NO}
For this relation in table , STUD_NO -> STUD_STATE and STUD_STATE ->
STUD_COUNTRY are true. So STUD_COUNTRY is transitively dependent
on STUD_NO. It violates the third normal form. To convert it in third normal
form, we will decompose the relation STUDENT (STUD_NO, STUD_NAME,
STUD_PHONE, STUD_STATE, STUD_COUNTRY_STUD_AGE) as:
Example
Find the highest normal form of a relation R(A, B, C, D, E) with FD set as:
Explanation:
Step-1: As we can see, (AC)+ ={A, C, B, E, D} but none of its subsets can
determine all attributes of the relation, So AC will be the candidate key. A or C
can’t be derived from any other attribute of the relation, so there will be only 1
candidate key {AC}.
Step-2: Prime attributes are those attributes that are part of candidate key {A, C}
in this example and others will be non-prime {B, D, E} in this example.
Step-3: The relation R is in 1st normal form as a relational DBMS does not allow
multi-valued or composite attributes.
12/20/2024 Dr. Gitanjali , Asst. Prof., UIE-CSE, Chandigarh University
Boyce-Codd Normal Form (BCNF)
Although, 3NF is an adequate normal form for relational databases, this (3NF)
normal form may not remove 100% redundancy because of X−>Y functional
dependency if X is not a candidate key of the given relation. This can be solved
by the Boyce-Codd Normal Form (BCNF).
Note –
In other words, 4NF states that no entity can have more than a single one-to-many
relationship within an entity if the one-to-many attributes are independent of each
other.
Definition: A table is in fourth normal form (4NF) if and only if it is in BCNF and
contains no more than one multi-valued dependency.
MovieOne UK
MovieOne UK
Let us convert the
above table in 4NF MovieTwo Australia
− MovieTwo Australia
<Movie_Shooting> MovieThree India
<Movie_Listing>
Now the violation is
Movie_Name Listing
removed and the
tables are in 4NF. MovieOne Comedy
MovieOne Thriller
MovieTwo Action
MovieTwo Crime
MovieThree Drama
EmpName EmpJob
David E145
EmpSkills EmpJob
John E146
Java E145
Jamie E146
JavaScript E146
Emma E147
jQuery E146
Java E147
Fifth normal form, also known as join-projection normal form (JPNF), states that no
non-trivial join dependencies exist. 5NF states that any fact should be able to be
reconstructed without any anomalous results in any case, regardless of the number
of tables being joined. A 5NF table should have only candidate keys and it's
primary key should consist of only a single column.
Result of Natural Join of R1 and R3 over ‘Company’ and then Natural Join of R13
and R2 over ‘Agent’and ‘Product’ will be table ACP.
Hence, in this example, all the redundancies are eliminated, and the
decomposition of ACP is a lossless join decomposition. Therefore, the relation is in
5NF as it does not violate the property of lossless join.
1. To have good understanding of database system concepts and design databases for
different applications.
2. To learn how to use a DBMS and RDBMS.
3. To implement and understand different types of DDL, DML and DCL statements.
4. To understand transaction concepts related to databases and recovery/backup
techniques required for the proper storage of data.
Database Security:
Introduction, Threats, Counter Measures.
■ Various legal and ethical issues regarding the right to access certain information—
for example, some information may be deemed to be private and cannot be accessed
legally by unauthorized organizations or persons.
■ System-related issues such as the system levels at which various security functions
should be enforced—for example, whether a security function should be handled at the
physical hardware level, the operating system level, or the DBMS level.
■ The need in some organizations to identify multiple security levels and to categorize
the data and users based on these classifications—for example, top secret, secret,
confidential, and unclassified.
Levels of Data Security
79
Physical/OS Security
• Physical level
– Traditional lock-and-key security
– Protection from floods, fire, etc.
• E.g. WTC (9/11), fires in IITM, WWW conf website, etc.
– Protection from administrator error
• E.g. delete critical files
– Solution
• Remote backup for disaster recovery
• Plus archival backup (e.g. DVDs/tapes)
• Authentication:
– who are you? Prove it!
• Authorization:
– what you are allowed to do
Network Security
Threat is any intentional or accidental event that may adversely affect the system.
Examples of threats:
Slide 23- 86
Control methods of Database Security
The following are the main control measures are used to provide security of
data in databases:
1. Authentication
2. Access control
3. Inference control
4. Flow control
5. Database Security applying Statistical Method
6. Encryption
Access Control:
The security mechanism of DBMS must include some provisions for restricting access to the
data base by unauthorized users. Access control is done by creating user accounts and to
control login process by the DBMS. So, that database access of sensitive data is possible only
to those people (database users) who are allowed to access such data and to restrict access
to unauthorized persons.
The database system must also keep the track of all operations performed by certain user
throughout the entire login time.
Captcha test Permissions – Read & Write access to files and allowing
Biometric Authentication access to the database.
Passwords Deciding the roles of users for accessing data
It’s controlled through the server for finding out who’s The server helps to decide that client has the authority to
accessing what data or site. access a resource or not.
Example: Employees authenticating through the network Example: Once an employee is authenticated, the different
before opening the company mails. system decides which information will be accessed by
which employee.
Flow Control:
This prevents information from flowing in a way
that it reaches unauthorized users. Channels are
the pathways for information to flow implicitly in
ways that violate the privacy policy of a company
are called convert channels.
Encryption:
This method is mainly used to protect sensitive data (such as
credit card numbers, OTP numbers) and other sensitive
numbers. The data is encoded using some encoding algorithms.
• The database administrator (DBA) is the central authority for managing a database
system.
• The DBA is responsible for the overall security of the database system.
Database Security and DBA
1. To have good understanding of database system concepts and design databases for
different applications.
2. To learn how to use a DBMS and RDBMS.
3. To implement and understand different types of DDL, DML and DCL statements.
4. To understand transaction concepts related to databases and recovery/backup
techniques required for the proper storage of data.
Control Structures :
Syntax :
Output :
reverse of given number is:
321
Syntax :
GOTO jump;
....
<<jump>>
code starts
before gotostatements
flow of execution jumped here.
1.Implicit cursors
2.Explicit cursors
%ROWCOUNT
It displays the number of rows produced by a SELECT INTO command or affected by DML
operations like INSERT, DELETE, and UPDATE.
• Fetch Data: Retrieve one row at a time from the result set.
• Close the Cursor: Release the resources associated with the cursor.
Disadvantages:
• Slower performance compared to set-based
operations.
• Increases code complexity.
• Declare the Cursor: Use the view in the SELECT query for the cursor declaration.
• Fetch Rows from the Cursor: Retrieve rows one at a time from the cursor.
• Process Each Row: Apply desired logic (e.g., calculations, updates) to the fetched data.
• Close the Cursor: Release resources after completing processing.
1.Simplicity:
⚬ Views can encapsulate complex queries,
making the cursor's logic simpler.
2.Reusability:
⚬ A view can be reused across different queries or
cursors.
3.Data Abstraction:
⚬ Views abstract the underlying table structure,
providing a layer of security and modularity.