Skip to content

Commit 7e805dc

Browse files
authored
Merge pull request #746 from Vipullakum007/dbms-docs-sec-3-4-5
Dbms docs sec 3 4 5 added
2 parents e3e2015 + aa3054f commit 7e805dc

File tree

8 files changed

+655
-0
lines changed

8 files changed

+655
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Relational Database Design",
3+
"position": 3,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Explore relational database design concepts, including the Relational Model, ER modeling, normalization, and more."
7+
}
8+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
id: dbms-joins
3+
title: DBMS - Joins
4+
sidebar_label: DBMS Joins
5+
sidebar_position: 2
6+
description: Explore different types of joins in database management systems and their applications.
7+
---
8+
9+
DBMS - Joins
10+
---
11+
12+
Joins in database management systems allow us to combine data from multiple tables based on specified conditions. Let's explore various types of joins:
13+
14+
Theta (θ) Join
15+
---
16+
17+
Theta join combines tuples from different relations based on a given theta condition denoted by the symbol θ. It can use various comparison operators.
18+
19+
```mermaid
20+
graph TD;
21+
A[Student] -->|Std| B[Subjects]
22+
B -->|Class| C[Student_Detail]
23+
```
24+
25+
Example of Theta Join:
26+
```plaintext
27+
Student
28+
SID Name Std
29+
101 Alex 10
30+
102 Maria 11
31+
32+
Subjects
33+
Class Subject
34+
10 Math
35+
10 English
36+
11 Music
37+
11 Sports
38+
39+
Student_Detail
40+
SID Name Std Class Subject
41+
101 Alex 10 10 Math
42+
101 Alex 10 10 English
43+
102 Maria 11 11 Music
44+
102 Maria 11 11 Sports
45+
```
46+
47+
Equijoin
48+
---
49+
50+
Equijoin is a type of theta join where only equality comparison operators are used. It matches tuples based on equal values of attributes.
51+
52+
Natural Join (⋈)
53+
---
54+
55+
Natural join combines tuples from two relations based on common attributes with the same name and domain. It does not use any comparison operator.
56+
57+
Example of Natural Join:
58+
```mermaid
59+
graph TD;
60+
A[Courses] -->|Dept| B[HoD]
61+
```
62+
63+
Result of Natural Join:
64+
```plaintext
65+
Courses ⋈ HoD
66+
Dept CID Course Head
67+
CS CS01 Database Alex
68+
ME ME01 Mechanics Maya
69+
EE EE01 Electronics Mira
70+
```
71+
72+
Outer Joins
73+
---
74+
75+
Outer joins include all tuples from participating relations, even if there are no matching tuples.
76+
77+
Left Outer Join (R Left Outer Join S)
78+
---
79+
80+
```plaintext
81+
Left
82+
A B
83+
100 Database
84+
101 Mechanics
85+
102 Electronics
86+
87+
Right
88+
A B
89+
100 Alex
90+
102 Maya
91+
104 Mira
92+
93+
Courses Left Outer Join HoD
94+
A B C D
95+
100 Database 100 Alex
96+
101 Mechanics --- ---
97+
102 Electronics 102 Maya
98+
```
99+
100+
Right Outer Join (R Right Outer Join S)
101+
---
102+
103+
```plaintext
104+
Courses Right Outer Join HoD
105+
A B C D
106+
100 Database 100 Alex
107+
102 Electronics 102 Maya
108+
--- --- 104 Mira
109+
```
110+
111+
Full Outer Join (R Full Outer Join S)
112+
---
113+
114+
```plaintext
115+
Courses Full Outer Join HoD
116+
A B C D
117+
100 Database 100 Alex
118+
101 Mechanics --- ---
119+
102 Electronics 102 Maya
120+
--- --- 104 Mira
121+
```
122+
123+
These joins are crucial for combining data effectively from multiple tables in database systems.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
id: dbms-normalization
3+
title: DBMS - Normalization
4+
sidebar_label: Normalization
5+
sidebar_position: 1
6+
description: Learn about Functional Dependency, Normalization, and different Normal Forms in Database Management Systems (DBMS).
7+
---
8+
9+
# DBMS - Normalization
10+
11+
## Functional Dependency
12+
13+
Functional dependency (FD) is a set of constraints between two attributes in a relation. Functional dependency says that if two tuples have the same values for attributes A1, A2,..., An, then those two tuples must have the same values for attributes B1, B2, ..., Bn.
14+
15+
Functional dependency is represented by an arrow sign (→) that is, $X \rightarrow Y$, where X functionally determines Y. The left-hand side attributes determine the values of attributes on the right-hand side.
16+
17+
### Armstrong's Axioms
18+
19+
If F is a set of functional dependencies then the closure of F, denoted as F+, is the set of all functional dependencies logically implied by F. Armstrong's Axioms are a set of rules, that when applied repeatedly, generates a closure of functional dependencies.
20+
21+
```mermaid
22+
graph TD;
23+
A["alpha"] -->|is_subset_of| B["beta"]
24+
B -->|alpha holds beta| C["alpha holds beta"]
25+
A -->|augmentation rule| D["ay → by also holds"]
26+
C -->|transitivity rule| E["a → c also holds"]
27+
```
28+
29+
## Trivial Functional Dependency
30+
31+
- **Trivial:** If a functional dependency (FD) X → Y holds, where Y is a subset of X, then it is called a trivial FD. Trivial FDs always hold.
32+
33+
- **Non-trivial:** If an FD X → Y holds, where Y is not a subset of X, then it is called a non-trivial FD.
34+
35+
- **Completely non-trivial:** If an FD X → Y holds, where x intersect Y = Φ, it is said to be a completely non-trivial FD.
36+
37+
## Normalization
38+
39+
If a database design is not perfect, it may contain anomalies, which are like a bad dream for any database administrator. Managing a database with anomalies is next to impossible.
40+
41+
- **Update anomalies** − If data items are scattered and are not linked to each other properly, then it could lead to strange situations. For example, when we try to update one data item having its copies scattered over several places, a few instances get updated properly while a few others are left with old values. Such instances leave the database in an inconsistent state.
42+
43+
- **Deletion anomalies** − We tried to delete a record, but parts of it was left undeleted because of unawareness, the data is also saved somewhere else.
44+
45+
- **Insert anomalies** − We tried to insert data in a record that does not exist at all.
46+
47+
Normalization is a method to remove all these anomalies and bring the database to a consistent state.
48+
49+
```mermaid
50+
graph TD;
51+
A[Update anomalies] -->|Inconsistent state| B[Database]
52+
C[Deletion anomalies] -->|Left undeleted parts| B
53+
D[Insert anomalies] -->|Insert data in non-existing record| B
54+
```
55+
56+
## First Normal Form (1NF)
57+
58+
First Normal Form is defined in the definition of relations (tables) itself. This rule defines that all the attributes in a relation must have atomic domains. The values in an atomic domain are indivisible units.
59+
60+
unorganized relation
61+
62+
```mermaid
63+
graph TD;
64+
A["Relation"] -->|Unorganized| B["1NF"]
65+
```
66+
67+
Each attribute must contain only a single value from its pre-defined domain.
68+
69+
## Second Normal Form (2NF)
70+
71+
Before we learn about the second normal form, we need to understand the following −
72+
73+
- **Prime attribute :** An attribute, which is a part of the candidate-key, is known as a prime attribute.
74+
75+
- **Non-prime attribute :** An attribute, which is not a part of the prime-key, is said to be a non-prime attribute.
76+
77+
```mermaid
78+
graph TD;
79+
A["Candidate Key"] -->|Part of| B["Prime Attribute"]
80+
C["Non-Prime Attribute"] -->|Not part of| A
81+
D["X → A holds"] -->|No subset Y → A| E["Second Normal Form"]
82+
```
83+
84+
## Third Normal Form (3NF)
85+
86+
For a relation to be in Third Normal Form, it must be in Second Normal form and the following must satisfy −
87+
88+
No non-prime attribute is transitively dependent on the prime key attribute.
89+
90+
```mermaid
91+
graph TD;
92+
A["X → A"] -->|Superkey or A is prime| B["Third Normal Form"]
93+
C["Transitive Dependency"] -->|Stu_ID → Zip → City| D["Relation not in 3NF"]
94+
```
95+
96+
## Boyce-Codd Normal Form (BCNF)
97+
98+
BCNF is an extension of Third Normal Form on strict terms. BCNF states that −
99+
100+
For any non-trivial functional dependency, X → A, X must be a super-key.
101+
102+
```mermaid
103+
graph TD;
104+
A["X → A"] -->|X is super-key| B["BCNF"]
105+
```
106+
107+
In the above image, Stu_ID is the super-key in the relation Student_Detail and Zip is the super-key in the relation ZipCodes. So,
108+
```
109+
Stu_ID → Stu_Name, Zip
110+
```
111+
and
112+
```
113+
Zip → City
114+
```
115+
Which confirms that both the relations are in BCNF.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"label": "Relational Model",
3+
"position": 2,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Explore the Relational Model in DBMS, its concepts, and its applications."
7+
}
8+
}
9+
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
id: codd-s-12-rules
3+
title: Codd's 12 Rules
4+
sidebar_label: Codd's 12 Rules
5+
sidebar_position: 1
6+
description: Explore Dr. Edgar F. Codd's 12 Rules for true relational databases with examples and diagrams.
7+
---
8+
9+
# DBMS - Codd's 12 Rules
10+
11+
Dr. Edgar F. Codd, after his extensive research on the Relational Model of database systems, came up with twelve rules of his own, which according to him, a database must obey in order to be regarded as a true relational database.
12+
13+
## Rule 1: Information Rule
14+
15+
The data stored in a database, may it be user data or metadata, must be a value of some table cell. Everything in a database must be stored in a table format.
16+
17+
### Example:
18+
19+
Consider a database for a library. The Information Rule ensures that every piece of data, like the title of a book or the name of an author, is stored within a specific table cell, such as the 'Book Title' attribute in the 'Books' table.
20+
21+
## Rule 2: Guaranteed Access Rule
22+
23+
Every single data element (value) is guaranteed to be accessible logically with a combination of table-name, primary-key (row value), and attribute-name (column value). No other means, such as pointers, can be used to access data.
24+
25+
### Example:
26+
27+
In a customer database, the Guaranteed Access Rule ensures that you can access a specific customer's details using their unique customer ID, such as querying "SELECT \* FROM Customers WHERE CustomerID = '123'".
28+
29+
## Rule 3: Systematic Treatment of NULL Values
30+
31+
The NULL values in a database must be given a systematic and uniform treatment. This is a very important rule because a NULL can be interpreted as one of the following − data is missing, data is not known, or data is not applicable.
32+
33+
### Example:
34+
35+
In an employee database, the Systematic Treatment of NULL Values ensures that if an employee's middle name is unknown or not applicable, it's represented as NULL in the database rather than an empty string or a placeholder.
36+
37+
## Rule 4: Active Online Catalog
38+
39+
The structure description of the entire database must be stored in an online catalog, known as data dictionary, which can be accessed by authorized users. Users can use the same query language to access the catalog which they use to access the database itself.
40+
41+
### Example:
42+
43+
An Active Online Catalog provides metadata about the database schema. For instance, it includes information about tables, columns, data types, and relationships, allowing users to understand and query the database structure.
44+
45+
```mermaid
46+
erDiagram
47+
CAT_TABLE ||--o{ DB_TABLE : has
48+
CAT_TABLE ||--o{ COLUMN : has
49+
DB_TABLE ||--o{ COLUMN : contains
50+
DB_TABLE }|..|{ DATA : stores
51+
```
52+
53+
## Rule 5: Comprehensive Data Sub-Language Rule
54+
55+
A database can only be accessed using a language having linear syntax that supports data definition, data manipulation, and transaction management operations. This language can be used directly or by means of some application. If the database allows access to data without any help of this language, then it is considered as a violation.
56+
57+
### Example:
58+
59+
SQL (Structured Query Language) is a comprehensive data sub-language that fulfills the requirements of data definition, manipulation, and transaction management. It allows users to interact with the database through standard commands like SELECT, INSERT, UPDATE, DELETE, and COMMIT.
60+
61+
## Rule 6: View Updating Rule
62+
63+
All the views of a database, which can theoretically be updated, must also be updatable by the system.
64+
65+
### Example:
66+
67+
Consider a view that combines data from multiple tables for reporting purposes. The View Updating Rule ensures that if the view includes columns from a single base table, those columns can be updated through the view.
68+
69+
## Rule 7: High-Level Insert, Update, and Delete Rule
70+
71+
A database must support high-level insertion, updation, and deletion. This must not be limited to a single row, that is, it must also support union, intersection and minus operations to yield sets of data records.
72+
73+
### Example:
74+
75+
The High-Level Insert, Update, and Delete Rule allows you to insert, update, or delete multiple rows at once. For instance, you can use an SQL statement like "DELETE FROM Employees WHERE Salary < 50000" to delete all employees with a salary below $50,000.
76+
77+
## Rule 8: Physical Data Independence
78+
79+
The data stored in a database must be independent of the applications that access the database. Any change in the physical structure of a database must not have any impact on how the data is being accessed by external applications.
80+
81+
### Example:
82+
83+
Physical Data Independence allows you to modify the storage structures (like changing indexes or file organization) without affecting how users and applications interact with the data. This ensures that applications remain functional even if the database undergoes structural changes.
84+
85+
## Rule 9: Logical Data Independence
86+
87+
The logical data in a database must be independent of its user’s view (application). Any change in logical data must not affect the applications using it. For example, if two tables are merged or one is split into two different tables, there should be no impact or change on the user application. This is one of the most difficult rules to apply.
88+
89+
### Example:
90+
91+
Imagine merging two tables 'Customers' and 'Suppliers' into a single table 'Partners'. Logical Data Independence ensures that existing applications accessing 'Customers' or 'Suppliers' continue to function seamlessly after the merge.
92+
93+
## Rule 10: Integrity Independence
94+
95+
A database must be independent of the application that uses it. All its integrity constraints can be independently modified without the need of any change in the application. This rule makes a database independent of the front-end application and its interface.
96+
97+
### Example:
98+
99+
Integrity constraints like primary keys, foreign keys, and unique constraints can be modified or added without affecting how applications interact with the database. This allows for changes in data validation rules without altering application logic.
100+
101+
## Rule 11: Distribution Independence
102+
103+
The end-user must not be able to see that the data is distributed over various locations. Users should always get the impression that the data is located at one site only. This rule has been regarded as the foundation of distributed database systems.
104+
105+
### Example:
106+
107+
In a distributed database, data may be stored across multiple physical locations. Distribution Independence ensures that users perceive and interact with the data as if it's stored in a single location, regardless of its actual distribution.
108+
109+
## Rule 12: Non-Subversion Rule
110+
111+
If a system has an interface that provides access to low-level records, then the interface must not be able to subvert the system and bypass security and integrity constraints.
112+
113+
### Example:
114+
115+
The Non-Subversion Rule prevents unauthorized access to low-level records or system components that could compromise security or integrity. It ensures that access controls and security measures are enforced, even through direct interfaces.
116+

0 commit comments

Comments
 (0)