UNIT 2-rdbms
UNIT 2-rdbms
Relational Query Languages are used to interact with and manipulate relational
databases. These languages allow users to retrieve, insert, delete, and update data
stored in a relational model.
σ condition (Relation)
Example: σ Salary > 50000 (Employees)
2. Projection (π): Selects specific columns.
π Column1, Column2 (Relation)
Example: π Name, Salary (Employees)
3. Union (∪): Combines results of two relations with no duplicates.
Relation1 ∪ Relation2
4. Set Difference (-): Finds tuples in one relation but not in another.
Relation1 - Relation2
5. Cartesian Product (×): Combines every tuple of one relation with every
tuple of another.
Relation1 × Relation2
6. Join: Combines related tuples from two relations.
Relation1 ⨝ Relation2
7. Division (÷): Finds tuples in one relation that match all tuples in
another.
Relation1 ÷ Relation2
Find the names and salaries of employees earning more than 50,000:
π Name, Salary (σ Salary > 50000 (Employees))
Using SQL
What is Normalization?
The main reason for normalizing the relations is removing these anomalies.
Failure to eliminate anomalies leads to data redundancy and can cause data
integrity and other problems as the database grows. Normalization consists of
a series of guidelines that helps to guide you in creating a good database
structure.
Advantages of Normalization
Disadvantages of Normalization
o You cannot start building the database before knowing what the user
needs.
o The performance degrades when normalizing the relations to higher
normal forms, i.e., 4NF, 5NF.
o It is very time-consuming and difficult to normalize relations of a higher
degree.
o Careless decomposition may lead to a bad database design, leading to
serious problems.
Need of Normalization?
The main reason for normalizing the relations is removing these anomalies.
Failure to eliminate anomalies leads to data redundancy and can cause data
integrity and other problems as the database grows. Normalization consists of
a series of guidelines that helps to guide you in creating a good database
structure.
Normal Description
Form
2NF
A relation will be in 2NF if it is in 1NF and all non-key
attributes are fully functional dependent on the primary key.
EMPLOYEE table:
7272826385,
14 John UP
9064738238
7390372389,
12 Sam Punjab
8589830302
The decomposition of the EMPLOYEE table into 1NF has been shown below:
EMP_ID EMP_NAME EMP_PHONE EMP_STATE
14 John 7272826385 UP
14 John 9064738238 UP
TEACHER table
25 Chemistry 30
25 Biology 30
47 English 35
83 Math 38
83 Computer 38
To convert the given table into 2NF, we decompose it into two tables:
TEACHER_DETAIL table:
TEACHER_ID TEACHER_AGE
25 30
47 35
83 38
TEACHER_SUBJECT table:
TEACHER_ID SUBJECT
25 Chemistry
25 Biology
47 English
83 Math
83 Computer
Third Normal Form (3NF)
1. X is a super key.
2. Y is a prime attribute, i.e., each element of Y is part of some candidate
key.
Example:
EMPLOYEE_DETAIL table:
That's why we need to move the EMP_CITY and EMP_STATE to the new
<EMPLOYEE_ZIP> table, with EMP_ZIP as a Primary key.
EMPLOYEE table:
EMPLOYEE_ZIP table:
201010 UP Noida
02228 US Boston
60007 US Chicago
06389 UK Norwich
462007 MP Bhopal
Relational Decomposition
Types of Decomposition
Lossless Decomposition
o If the information is not lost from the relation that is decomposed, then
the decomposition will be lossless.
o The lossless decomposition guarantees that the join of relations will
result in the same relation as it was decomposed.
o The relation is said to be lossless decomposition if natural joins of all
the decomposition give the original relation.
Example:
EMPLOYEE_DEPARTMENT table:
EMPLOYEE table:
22 Denim 28 Mumbai
33 Alina 25 Delhi
46 Stephan 30 Bangalore
52 Katherine 36 Mumbai
60 Jack 40 Noida
DEPARTMENT table
827 22 Sales
438 33 Marketing
869 46 Finance
575 52 Production
678 60 Testing
Now, when these two relations are joined on the common column "EMP_ID",
then the resultant relation will look like:
Employee ⋈ Department
Dependency Preserving
Oracle Database and IBM Db2 are two popular Relational Database Management
Systems (RDBMS) widely used in enterprise environments. Both have distinct
features, strengths, and use cases. Here's a detailed comparison:
Oracle Database:
1. High Availability: Real Application Clusters (RAC) and Data Guard offer
excellent fault tolerance and disaster recovery.
2. Autonomous Features: Self-tuning and machine learning-driven
optimizations.
3. Broad Application Support: Widely used across diverse industries for
enterprise applications.
4. Multi-Model Database: Supports relational, document (JSON), spatial, and
graph data.
IBM Db2: