DBMS RDBMS NOTES Important
DBMS RDBMS NOTES Important
DBMS RDBMS NOTES Important
UNIT – 1
- **Data**: Raw facts and figures without context. Data can be numbers,
Each row is a record with a unique ID called the primary key. Each column
databases.
- **Functions of a DBMS**:
security.
applications.
- **Procedures**: Instructions and rules that govern the design and use of
the database.
breaches.
consistency.
levels).
simultaneously.
unified view.
case of failure.
developed by Microsoft.
information.
2. **Healthcare**:
- **Electronic Health Records (EHR)**: Systems like Epic and Cerner store
patient outcomes.
3. **Education**:
academic records.
4. **E-commerce**:
pricing.
shipping information.
5. **Government**:
revenue collection.
6. **Telecommunications**:
processing.
level of a database system without altering the schema at the next higher
schema without changing the logical schema. This ensures that changes in
programs.
applications.
ensures that changes in the logical structure of the database do not affect
and manipulation.
failures.
training expenses.
Database management systems are essential for efficient and secure data
management.
Management System)
#### Definitions
that stores data in tables (relations) which are linked to each other through
keys. It uses a structured query language (SQL) for database access and
manipulation.
1. **Data Structure**:
- **DBMS**: Data is stored in files. The structure can vary and may include
2. **Data Relationships**:
3. **Data Integrity**:
4. **Query Language**:
- **DBMS**: May use various languages or methods for data access and
5. **Normalization**:
6. **Data Redundancy**:
of relational constraints.
transaction processing.
8. **Examples**:
Server.
9. **Scalability**:
models, such as hierarchical and network, which might be more suitable for
certain applications.
- **Ease of Data Access and Management**: The use of SQL makes data
### Conclusion
offers a more structured and reliable way to manage data through its
tabular format, relationships, and use of SQL. The choice between DBMS
as the need for data integrity, complexity of data relationships, and query
capabilities.
#### 1. Entities
**Entities** are objects or things in the real world that are distinguishable
item that we need to store data about. Entities are typically the tables in a
relational database.
type.
**Examples of Entities**:
#### 2. Attributes
`LastName`.
`Age`.
Example: `PhoneNumbers`.
**Examples of Attributes**:
- **Customer Entity**:
- `FirstName`
- `LastName`
- `Email`
- `PhoneNumber`
- **Product Entity**:
- `ProductName`
- `Price`
- `StockQuantity`
- **Order Entity**:
- `OrderDate`
- `TotalAmount`
are the columns in these tables. Each row in a table represents an entity
instance, and the values in each row correspond to the attribute values for
**Example Schema**:
- **Table: Customers**
`PhoneNumber`
- **Table: Products**
`StockQuantity`
- **Table: Orders**
### Example
- **Entities**:
- `Book`
- `Member`
- `Loan`
- **Attributes**:
- **Book**:
- `BookID`
- `Title`
- `Author`
- `Publisher`
- `ISBN`
- **Member**:
- `MemberID`
- `FirstName`
- `LastName`
- `Email`
- `MembershipDate`
- **Loan**:
- `LoanID`
- `BookID`
- `MemberID`
- `LoanDate`
- `ReturnDate`
In this example:
- The `Book` entity has attributes like `BookID`, `Title`, and `Author`.
`LastName`.
- The `Loan` entity links the `Book` and `Member` entities through the
UNIT – 2
storage details.
- Includes the logical schema which defines the structure and constraints
of the data.
1. **Presentation Tier**:
interfaces.
### Schema
database architecture:
1. **Internal Schema**:
2. **Conceptual Schema**:
1. **Instance**:
- **Memory Structures**:
- **Program Global Area (PGA)**: Private memory area for each server
- **Log Writer (LGWR)**: Writes redo log entries from the redo log buffer
instance starts.
checkpoint information.
- **Archiver (ARCn)**: Archives redo log files when they are full or at
regular intervals.
2. **Storage Structures**:
- **Redo Log Files**: Record all changes made to the data to provide data
recovery.
indexes.
```
+-----------------------------------+
| User Process |
+-----------------------------------+
+-----------------------------------+
| Server Process |
+-----------------------------------+
+-----------------------------------+ +-----------------------------------+
| - Large Pool |
| - Java Pool |
+-----------------------------------+
+-----------------------------------+
| Background Processes |
| - ARCn, ... |
+-----------------------------------+
+-----------------------------------+ +-----------------------------------+
+-----------------------------------+
```
### Summary
external levels.
redo log files, control files), along with logical storage structures like
### Data Definition Language (DDL) and Data Manipulation Language (DML)
define and manage database schemas and objects such as tables, indexes,
and constraints. DDL commands do not manipulate the data itself but define
1. **CREATE**:
```sql
FirstName VARCHAR(50),
LastName VARCHAR(50),
BirthDate DATE,
HireDate DATE,
Salary DECIMAL(10, 2)
);
```
2. **ALTER**:
```sql
```
3. **DROP**:
```sql
```
4. **TRUNCATE**:
- Used to remove all records from a table, but not the table itself.
```sql
```
5. **COMMENT**:
```sql
```
6. **RENAME**:
```sql
```
retrieve, insert, update, and delete data within database tables. DML
1. **SELECT**:
```sql
```
```sql
```
2. **INSERT**:
```sql
HireDate, Salary)
```
3. **UPDATE**:
```sql
UPDATE Employees
WHERE EmployeeID = 1;
```
4. **DELETE**:
```sql
WHERE EmployeeID = 1;
```
```sql
DepartmentName VARCHAR(100)
);
FirstName VARCHAR(50),
LastName VARCHAR(50),
DepartmentID INT,
BirthDate DATE,
HireDate DATE,
Departments(DepartmentID)
);
```
```sql
VALUES
-- Selecting records
-- Updating records
UPDATE Employees
WHERE EmployeeID = 2;
-- Deleting records
WHERE EmployeeID = 1;
```
### Summary
- **DDL**: Used for defining and managing database schemas and objects.
organization. Both roles are crucial for the effective management and
organization. The Database Manager may oversee a team of DBAs and other
**Key Responsibilities**:
1. **Strategic Planning**:
objectives.
2. **Team Management**:
professionals.
5. **Stakeholder Communication**:
day operations of database systems. DBAs are responsible for ensuring that
databases are available, secure, and performing optimally. They handle the
**Key Responsibilities**:
for use.
upgrades.
3. **Security Management**:
- Creating and testing backup and recovery plans to prevent data loss.
failure.
5. **Performance Tuning**:
Server, MySQL).
### Comparison
(DBA) |
|---------------------------|-----------------------------------------|-----------------------------------------|
database operations |
operational |
security management |
### Summary
database systems.
Both roles are essential for the successful management and operation of
1. **Metadata**:
2. **Data Definitions**:
values.
3. **Relationships**:
4. **Usage Information**:
5. **Business Rules**:
Constraints |
|------------|--------------|-----------|------|------------------------------|----------------------|
PRIMARY KEY |
| NOT NULL |
| NOT NULL |
performance.
1. **Client**:
- The client is the frontend component that interacts directly with users.
2. **Server**:
data management, making the system more modular and easier to maintain.
increasing loads.
1. **Two-Tier Architecture**:
2. **Three-Tier Architecture**:
- **Data Tier**: Database servers that manage data storage and retrieval.
- Example: Web applications where the client interacts with a web server,
3. **N-Tier Architecture**:
architectures.
1. **Presentation Tier**:
2. **Application Tier**:
3. **Data Tier**:
```
(3) Application server interacts with the database server to retrieve or store
data.
```
### Summary
Unit – 3
Database models define the structure, storage, and retrieval methods for
operations.
relationships.
**Example**:
```
Company
├── Department
│ ├── Employee
│ └── Employee
└── Department
├── Employee
└── Employee
```
structure.
to-many relationships.
**Example**:
```
Projects
├── Employee
│ └── Department
└── Department
└── Employee
```
or complex queries.
**Example**:
```
Table: Customers
+------------+----------+-----------+
+------------+----------+-----------+
Table: Orders
+---------+------------+----------+
+---------+------------+----------+
```
programming.
applications.
**Example**:
```java
class Employee {
int employeeID;
String firstName;
String lastName;
Department department;
class Department {
int departmentID;
String departmentName;
```
a flexible schema.
```json
"customerID": "12345",
"orders": [
"orderID": "987",
"total": 100.00
```
logic.
redundancy.
**Example**:
```json
"customerID:12345": {
"email": "john.doe@example.com"
},
"orderID:987": {
"customerID": "12345",
"total": 100.00
```
column families.
**Example**:
```
+-------+-------------------+---------------------+
+-------+-------------------+---------------------+
+-------+-------------------+---------------------+
```
operations.
**Example**:
```
```
### Summary
relationships.
languages.
schema.
data.
data.
the constraints and rules governing the data. It serves as a blueprint for
Data models can be classified into several types based on their structure
**Structure**:
- Data is organized into a tree-like structure with a single root and multiple
- Each parent can have multiple children, but each child has only one parent.
**Use Cases**:
**Advantages**:
**Disadvantages**:
hierarchy.
**Example**:
```
Company
├── Department
│ ├── Employee
│ └── Employee
└── Department
├── Employee
└── Employee
```
**Structure**:
(relationships).
**Use Cases**:
networks.
**Advantages**:
**Disadvantages**:
**Example**:
```
Projects
├── Employee
│ └── Department
└── Department
└── Employee
```
**Structure**:
- Data is organized into tables (relations) with rows (records) and columns
(attributes).
**Use Cases**:
**Advantages**:
**Disadvantages**:
**Example**:
```
Table: Customers
+------------+----------+-----------+
+------------+----------+-----------+
Table: Orders
+---------+------------+----------+
+---------+------------+----------+
```
**Structure**:
**Use Cases**:
of data.
**Advantages**:
**Disadvantages**:
**Example**:
```
| |
+--CustomerID +--OrderID
+--Name +--Date
+--Email +--Total
```
**Structure**:
**Use Cases**:
**Advantages**:
**Disadvantages**:
**Example**:
```java
class Employee {
int employeeID;
String firstName;
String lastName;
Department department;
class Department {
int departmentID;
String departmentName;
```
**Structure**:
schema.
**Use Cases**:
**Advantages**:
**Disadvantages**:
```json
"customerID": "12345",
"orders": [
"orderID": "987",
"total": 100.00
```
**Structure**:
- The value can be a string, number, JSON, or any other type of data.
**Use Cases**:
preferences.
**Advantages**:
**Disadvantages**:
**Example**:
```json
"customerID:12345": {
"email": "john.doe@example.com"
},
"orderID:987": {
"customerID": "12345",
"total": 100.00
```
**Structure**:
- Data is stored in columns rather than rows, grouped into column families.
- Each column family can contain multiple rows, with each row having a
unique key.
**Use Cases**:
**Advantages**:
- Highly scalable.
**Disadvantages**:
models.
**Example**:
```
+-------+-------------------+---------------------+
+-------+-------------------+---------------------+
+-------+-------------------+---------------------+
```
**Structure**:
**Use Cases**:
**Advantages**:
- Flexible schema.
**Disadvantages**:
relational databases.
**Example**:
```
```
### Summary
data.
relationships.
used.
- **Key-Value Data Model (NoSQL)**: Key-value pairs, simple and fast for
Different data models are optimized for various types of applications and
- **Structure**:
columns (attributes).
- Each table has a unique name and each column has a unique name within
the table.
- **Key Concepts**:
- **Advantages**:
- **Disadvantages**:
- **Example**:
```sql
Name VARCHAR(100),
Email VARCHAR(255)
);
CustomerID INT,
Total DECIMAL(10,2),
);
```
- **Structure**:
- Each child has only one parent, but a parent can have multiple children.
- **Key Concepts**:
- **Advantages**:
- **Disadvantages**:
- **Example**:
```
Company
├── Department
│ ├── Employee
│ └── Employee
└── Department
├── Employee
└── Employee
```
- **Structure**:
- **Key Concepts**:
- **Advantages**:
model.
- **Disadvantages**:
- **Example**:
```
Projects
├── Employee
│ └── Department
└── Department
└── Employee
```
- **Structure**:
behaviors.
- **Key Concepts**:
types.
- **Advantages**:
- **Disadvantages**:
- **Example**:
```java
class Employee {
int employeeID;
String firstName;
String lastName;
Department department;
class Department {
int departmentID;
String departmentName;
```
- **Structure**:
relationships of data.
- **Key Concepts**:
- **Advantages**:
- **Disadvantages**:
- **Example**:
```
| |
+--CustomerID +--OrderID
+--Name +--Date
+--Email +--Total
```
### Summary
supports SQL.
relationships.
- **Network Data Model**: Graph structure with nodes and edges, supports
many-to-many relationships.
oriented features.
These data models serve as frameworks for organizing and structuring data
in database systems, each with its own strengths and suitability for
Unit – 4
(fields).
modifications).
interference.
E.F. Codd established 12 rules (also known as Codd's Rules) to define what
rules include:
accessible via its table name, primary key, and column name.
be stored in the system catalog, which can be queried using the same query
support at least one relational language that has a well-defined syntax and
semantics.
6. **Rule 6: View Updating Rule**: All views that are theoretically updatable
7. **Rule 7: High-level Insert, Update, and Delete**: The DBMS must support
are altered.
restructuring) occur.
programs.
redundancy and improve data integrity. It involves dividing large tables into
values.
- Meet the requirements of 1NF and ensure all non-key attributes are fully
ensuring that all attributes are functionally dependent only on the primary
key.
and `StudentName`.
### Summary
of data.
triggers, constraints.
into a table.
table.
prone.
**Example**:
Non-1NF Table:
|-----------|-------------|-----------------|
1NF Table:
|-----------|-------------|----------|
|1 | John | Math |
|1 | John | Science |
- It is in 1NF.
primary key.
**Example**:
1NF Table:
|-----------|----------|-------------|------------|
2NF Tables:
Students Table:
| StudentID | StudentName |
|-----------|-------------|
|1 | John |
Courses Table:
| CourseID | CourseName |
|----------|------------|
| 101 | Math |
| 102 | Science |
Enrollment Table:
| StudentID | CourseID |
|-----------|----------|
|1 | 101 |
|1 | 102 |
- It is in 2NF.
**Example**:
2NF Table:
|-----------|----------|------------|------------------|
3NF Tables:
Instructors Table:
| Instructor | InstructorOffice |
|------------|------------------|
Enrollment Table:
|-----------|----------|------------|
- It is in 3NF.
**Example**:
3NF Table:
|----------|------------|----------|
BCNF Tables:
Courses Table:
| CourseID | Schedule |
|----------|----------|
InstructorAssignments Table:
| CourseID | Instructor |
|----------|------------|
- It is in BCNF.
**Example**:
|-----------|----------|-----------|
|1 | 101 | Reading |
|1 | 101 | Swimming |
|1 | 102 | Reading |
|1 | 102 | Swimming |
4NF Tables:
Students Table:
| StudentID | CourseID |
|-----------|----------|
|1 | 101 |
|1 | 102 |
Hobbies Table:
| StudentID | Hobby |
|-----------|-----------|
|1 | Reading |
|1 | Swimming |
- It is in 4NF.
**Example**:
|----------|------------|-------|
5NF Tables:
Courses Table:
| CourseID | Instructor |
|----------|------------|
Rooms Table:
| CourseID | Room |
|----------|-------|
| 101 | R101 |
| 101 | R102 |
InstructorAssignments Table:
| Instructor | Room |
|------------|-------|
### Summary
improve integrity.
is a super key.
loss of information.
Unit - 5
**SQL Operators**:
**SQL Functions**:
`SUBSTRING()`
`DATE_SUB()`
```sql
FROM table_name;
```
**Types of Queries**:
```sql
```
```sql
FROM Employees
Departments.DepartmentID;
```
```sql
SELECT Name
FROM Employees
```
The `GROUP BY` clause is used to group rows that have the same values in
**Example**:
```sql
FROM Employees
GROUP BY DepartmentID;
```
**INSERT Statement**:
```sql
```
**UPDATE Statement**:
```sql
UPDATE Employees
SET DepartmentID = 3
WHERE EmployeeID = 1;
```
**DELETE Statement**:
```sql
WHERE EmployeeID = 1;
```
```sql
Name VARCHAR(100),
DepartmentID INT,
HireDate DATE
);
```
```sql
```
```sql
```
**SELECT Statement**:
```sql
FROM Employees
WHERE DepartmentID = 2;
```
**INSERT Statement**:
```sql
VALUES ('HR');
```
**UPDATE Statement**:
```sql
UPDATE Employees
WHERE EmployeeID = 1;
```
**DELETE Statement**:
```sql
WHERE DepartmentID = 3;
```
removes duplicates.
```sql
UNION
```
statements.
```sql
INTERSECT
```
- **EXCEPT** (or MINUS): Returns records from the first SELECT statement
```sql
EXCEPT
```
- **INNER JOIN**: Returns records that have matching values in both tables.
```sql
FROM Employees
Departments.DepartmentID;
```
- **LEFT JOIN**: Returns all records from the left table, and matched
```sql
FROM Employees
Departments.DepartmentID;
```
- **RIGHT JOIN**: Returns all records from the right table, and matched
```sql
FROM Employees
Departments.DepartmentID;
```
- **FULL JOIN**: Returns all records when there is a match in either left or
right table.
```sql
FROM Employees
Departments.DepartmentID;
```
**Aggregate Functions**:
```sql
```
```sql
```
```sql
```
```sql
```
```sql
```
```sql
```
```sql
```
```sql
```
```sql
```
### Summary
statements.
- **Null Values**: Handling nulls with `IS NULL`, `IS NOT NULL`, `COALESCE`,
`IFNULL`.
Unit – 6
**Key Techniques**:
detection in emails).
**Applications**:
- Fraud detection.
- Customer retention.
current and historical data in one single place that is used for creating
**Design Principles**:
**Components**:
management.
areas.
**Design**:
normalized dimensions.
planning.
**Key Concepts**:
**Types of OLAP**:
**Operations**:
**ACID Properties**:
**Concurrency Control**:
concurrent access.
timestamps.
**Types of Failures**:
transaction to fail.
data.
**Recovery Techniques**:
operations.
recovery time.
2. **Redo**: Redo all operations from the log to ensure all operations are
database consistency.
### Summary
data.