SQL_Keys_Normalization_DBA
SQL_Keys_Normalization_DBA
1
KEYS in DBMS
• Primary key
• Alternate key
• Candidate key
• Foreign key
• Composite key
• Surrogate key
2
Primary Key
3
Alternate Key
4
Candidate Key
Stud ID, Roll No, and email are candidate keys which altogether help us
to uniquely identify the student record in the table.
5
Foreign Key
6
Composite Key
Here course code and StudID are not showing uniqueness but course
code, studID altogether shows uniqueness to table data. So, these
two attributes are a set of composite key
7
Surrogate Key
8
Joins
• Joins help retrieving data from two or more database tables into a single
result set.
• The tables are mutually related using primary and foreign keys.
• Inner join - The inner JOIN is used to return rows from both tables that satisfy
the given condition.
• Left Join - The LEFT JOIN returns all the rows from the table on the left even
if no matching rows have been found in the table on the right. Where no
matches have been found in the table on the right, NULL is returned.
• Right Join - RIGHT JOIN is obviously the opposite of LEFT JOIN. The RIGHT
JOIN returns all the columns from the table on the right even if no matching
rows have been found in the table on the left. Where no matches have been
found in the table on the left, NULL is returned.
• Outer Join - Outer JOINs return all records matching from both tables .
9
Firstname Lastname Start Time End Time
Anne Smith 09:00 18:00
Jack Francis 08:00 17:00
Anna McLean 11:00 20:00
Shown Willam 14:00 23:00
11
Normalization of data
Why do we normalize data?
• Eliminate repeated data
• To ensure data dependencies make some logical
sense
12
Consider this is the dataset :
Cust Item Shipping Supplier Supplier Price
Name Address Phone
Alan Xbox 35, Palm St, Microso (800) BUY- 250
Smith One Miami ft XBOX
Roger PlayStat 47 Campus Sony (800) BUY- 300
Banks ion 4 Rd, Boston SONY
13
1st Normal Form
• A single cell can not hold multiple values
14
2nd Normal Form
•1st NF
•All attributes should depend on key
15
3rd Normal Form
16
3rd Normal Form
17
BCNF (Boyce–Codd normal form)
• 3NF
• For every Functional Dependency, Left Hand Side attribute is super
key.
Not in BCNF
18
In BCNF
4th Normal Form
19
20
Resources :
https://www.freecodecamp.org/news/learn-sql-queries-database-
query-tutorial-for-beginners/ - SQL queries
https://www.guru99.com/joins.html - joins
https://www.youtube.com/watch?v=ABwD8IYByfk - normalization
21