DBMS 6 Days Traiining Plan
DBMS 6 Days Traiining Plan
Day 1
Introduction to DBMS
Data Models
Database Relationship Concepts
SQL Basics
Day 2
Day 3
Stored Procedures and Functions
Database Design and Normalization
Entity-Relationship (ER) Diagrams
Denormalization and its use cases
Day 4
Indexing and Query Optimization
Performance Tuning
NoSQL Databases: Introduction and Comparison with SQL
Use cases for NoSQL (Document, Key-Value, Column-
Family, Graph Databases)
Day 5-6
Practice
Day 1
🔷 Introduction to DBMS
Types and Importance
Difference between DBMS and RDBMS
Introduction to DBMS:
A Database Management System (DBMS) is a software application that allows users to
interact with databases. It facilitates the creation, management, retrieval, and
manipulation of data in a structured format.
01
Difference between DBMS and RDBMS:
DBMS (Database Management System) and RDBMS (Relational Database Management
System) are both software systems used for managing databases, but they have some key
differences.
DBMS can manage any type of database structure, while RDBMS specifically deals
with relational databases, where data is organized into tables with rows and columns.
RDBMS enforces a set of rules known as ACID properties (Atomicity, Consistency,
Isolation, Durability) to ensure data consistency and integrity, which is not always the
case with DBMS.
RDBMS typically supports SQL (Structured Query Language) for querying and
managing data, whereas DBMS may have its own proprietary language or support a
variety of query languages.
🔷 Data Models
Hierarchical, Network, Relational, Object-oriented
1. Hierarchical Model
Structure: Organizes data in a tree-like hierarchy, with parent-child relationships.
Example: Organizational charts, file systems.
Pros: Fast access and updates for hierarchical data.
Cons: Rigid structure, difficult to rearrange relationships.
02
2. Network Model
Structure: Uses a graph-like structure where nodes (records) can have multiple
relationships.
Example: Social networks, complex organizational structures.
Pros: Flexible connections, more natural representation for complex relationships.
Cons: More complex to design and maintain.
3. Relational Model
Structure: Organizes data into tables (relations) with rows and columns.
Example: Customer databases, sales records.
Pros: Easy to use, powerful querying with SQL, flexible data relationships.
Cons: Can be less efficient for highly interconnected data.
03
4. Object-Oriented Model
Structure: Stores data as objects, similar to object-oriented programming.
Example: CAD systems, multimedia applications.
Pros: Good for complex data types, integration with object-oriented programming.
Cons: Less mature than relational systems, can be more complex to implement.
1. Primary Key
Definition: A unique identifier for each record in a table.
Properties:
Must contain unique values.
Cannot be NULL.
Example: A Roll_No in a student database.
04
2. Foreign Key
Definition: A field (or collection of fields) in one table that uniquely identifies a
row of another table.
Properties:
Creates a link between two tables.
Ensures referential integrity.
Example: ID in Student Marks referencing ID in a Student Details.
3. Candidate Key
Definition: A field, or combination of fields, that can qualify as a unique
identifier for rows in a table.
Properties:
Must contain unique values.
There can be multiple candidate keys in a table.
Example: Both EmpId and EmpLicence in a table 1 could be candidate keys.
05
4. Superkey
Definition: A set of one or more columns that, taken together, can uniquely
identify a row in a table.
Properties:
Includes all candidate keys and possibly additional attributes.
Every table has at least one superkey (the set of all columns).
Example: A combination of primary key, candidate key and alternate key.
🔷 SQL Basics
Introduction to SQL
Data Definition Language (DDL): CREATE, ALTER, DROP
Data Manipulation Language (DML): INSERT, UPDATE, DELETE
Data Query Language (DQL): SELECT
Basic SELECT queries with WHERE, ORDER BY, GROUP BY,
HAVING clauses
06
Introduction to SQL
SQL, or Structured Query Language, is a standardized
programming language used for managing relational
databases. It encompasses various commands categorized
primarily into Data Definition Language (DDL), Data
Manipulation Language (DML), and Data Query Language
(DQL). Here’s a brief introduction to these SQL categories
and basic query structures:
07
1. Data Definition Language (DDL)
CREATE
Used to create a new database, table, or other database objects.
ALTER
Used to modify an existing database object, such as a table, to add, modify, or
drop columns.
08
DROP
Used to delete an existing database object, like a table or database.
UPDATE
The UPDATE statement is used to modify existing rows in a table. It can target
specific rows based on conditions or update all rows in a table.
09
DELETE
The DELETE statement is used to remove rows from a table. Like UPDATE, it can
target specific rows based on conditions or delete all rows.
10
4. Basic SELECT queries with WHERE, ORDER BY, GROUP BY, HAVING clauses
WHERE
The WHERE clause filters records that meet specified conditions.
ORDER BY
The ORDER BY clause sorts the result set by one or more columns in ascending
(ASC) or descending (DESC) order.
GROUP BY
The GROUP BY clause groups rows that share a value in specified columns into
summary rows. It is often used with aggregate functions like COUNT, SUM, AVG,
MIN, and MAX.
11
HAVING
The HAVING clause filters groups based on a specified condition. It is similar to the
WHERE clause but applies to aggregated data after the GROUP BY operation.
Day 2
🔷 Advanced SQL and Database Design
Advanced SQL
12
JOINS
JOINs in SQL are used to combine rows from two or more tables based on a
related column. The main types of JOINs are INNER JOIN, LEFT JOIN, RIGHT JOIN,
and FULL JOIN. Here’s an in-depth look at each type:
1. INNER JOIN
The INNER JOIN returns only the rows that have matching values in both tables. It
excludes rows that do not have matches in both tables.
13
2. LEFT JOIN
The LEFT JOIN returns all rows from the left table, and the matched rows from the
right table. Unmatched rows from the right table will result in NULL in the output.
3. RIGHT JOIN
The RIGHT JOIN returns all rows from the right table, and the matched rows from
the left table. Unmatched rows from the left table will result in NULL in the output.
14
4. FULL JOIN
The FULL JOIN returns all rows when there is a match in either table. It combines
the result of both LEFT JOIN and RIGHT JOIN. Unmatched rows from either table
will show NULL.
15
🔷 Views, Indexes, and Transactions
Views
Views are virtual tables that store SQL query results without storing the data
physically. They can be used for simplifying complex queries, providing security by
restricting access to specific data, and presenting data in a particular format.
Key Points
Definition: A view is a saved SQL query that acts like a table.
Creation: Created using the CREATE VIEW statement.
Use: Simplifies complex queries, provides security, and abstracts the
underlying tables.
Updatability: Some views are updatable, meaning you can use INSERT,
UPDATE, or DELETE on them, but this depends on how the view is defined.
Indexes
Indexes improve query performance by allowing the database to find rows more
quickly. They are like pointers to data in a table and can significantly speed up
SELECT, WHERE, and JOIN operations.
Key Points
Definition: A database object that improves the speed of data retrieval.
Creation: Created using the CREATE INDEX statement.
Types: Common types include B-tree (default), unique, composite (multiple
columns), and full-text indexes.
Trade-off: While indexes speed up read operations, they can slow down
INSERT, UPDATE, and DELETE operations because the index itself needs to be
updated.
Explain different type of indexes, how to create Indexes, and benefit of it.
16
Transactions
Transactions ensure that a series of SQL operations are executed as a single unit,
providing atomicity, consistency, isolation, and durability (ACID properties). They
ensure that either all operations are completed successfully or none are applied,
maintaining data integrity.
Key Points
Definition: A sequence of operations performed as a single logical unit of work.
Commands: BEGIN TRANSACTION, COMMIT, ROLLBACK.
ACID Properties: Ensures data integrity by making operations atomic (all-or-
nothing), consistent, isolated (operations appear sequential), and durable
(changes are permanent once committed).
🔷 ACID Properties
ACID Properties are a set of principles that ensure reliable processing of database
transactions, crucial for maintaining data integrity and consistency. Here’s a
concise overview of each property:
17
1. Atomicity
Atomicity ensures that a transaction is treated as a single, indivisible unit. This
means that all operations within the transaction must be completed successfully;
otherwise, none of them are applied.
Key Points
All-or-Nothing: If any part of the transaction fails, the entire transaction is
rolled back.
Ensures: No partial updates occur, maintaining consistency.
Implementation: Usually managed by the database's transaction management
system.
2. Consistency
Consistency ensures that a transaction brings the database from one valid state to
another, maintaining data integrity constraints.
Key Points
Data Validity: Ensures that all rules, such as foreign keys, triggers, and
constraints, are obeyed.
Before and After: Database should be in a consistent state both before and
after the transaction.
Implementation: Managed by the database schema and constraints.
18
3. Isolation
Isolation ensures that concurrent transactions do not interfere with each other,
leading to consistent results as if transactions were processed sequentially.
Key Points
Independent Execution: Transactions appear as though they are executed in
isolation.
Prevents Issues: Avoids problems like dirty reads, non-repeatable reads, and
phantom reads.
Levels: Isolation levels (e.g., READ UNCOMMITTED, READ COMMITTED,
REPEATABLE READ, SERIALIZABLE) define how isolation is enforced.
4. Durability
Durability ensures that once a transaction has been committed, it will remain so,
even in the event of a system failure.
Key Points
Permanent Changes: Committed data is saved and will survive crashes, power
losses, etc.
Reliability: Data is written to non-volatile storage, ensuring recovery.
Implementation: Managed by the database through logging and recovery
mechanisms.
19
Day 3
Key Points
Encapsulation: Groups multiple SQL statements into a single execution unit.
Performance: Reduces network traffic by executing on the server side.
Parameters: Can accept input (IN), output (OUT), or both (INOUT) parameters.
Control Flow: Can include conditional logic (IF, CASE), loops (WHILE, FOR), and
error handling.
20
Functions
Functions are routines that return a single value or a table and are typically used
for calculations or data transformation. Unlike stored procedures, functions must
return a value and are often used within SQL statements.
Key Points
Return Value: Must return a single value or a table.
Usage: Can be used in SQL statements (e.g., SELECT, WHERE, JOIN).
Parameters: Accept input parameters but do not return output parameters.
Deterministic: Ideally should not modify the database state, making them
predictable.
Key Characteristics
Automatic Execution: Triggers run automatically when specified events occur
(INSERT, UPDATE, DELETE).
Event-Based: Defined to respond to specific actions on a table or view.
Timing: Can execute BEFORE or AFTER the triggering event
21
🔷 Database Design and Normalization
Database Design Principles
Entity-Relationship (ER) Diagrams
Normalization (1NF, 2NF, 3NF, BCNF)
Denormalization and its use cases
2. Redundancy Minimization
Avoid duplicating data to reduce storage costs and minimize update anomalies.
Use normalization techniques to decompose tables into smaller, related tables,
removing redundant data.
22
4. Flexibility and Extensibility
Allow the database to adapt to changing requirements.
Use modular designs and keep schema changes minimal.
Ensure new data can be added without significant restructuring.
5. Security
Protect data from unauthorized access.
Implement appropriate access controls and encryption.
Key Components
Entity: A real-world object or concept represented by a table. Each entity has
attributes.
Example: Customer entity with attributes CustomerID, Name, Email.
Attribute: A property or characteristic of an entity.
Example: CustomerID, Name, Email for Customer entity.
Relationship: A link between entities that represents how they interact.
Example: A Customer places an Order.
23
🔷 Normalization (1NF, 2NF, 3NF, BCNF)
What is Normalization ?
Normalization (1NF, 2NF, 3NF, BCNF) is the process of organizing data in a
database to minimize redundancy and dependency.
1NF: Ensures each column contains atomic values and each row is unique.
2NF: All non-key attributes are fully functionally dependent on the entire
primary key.
3NF: Non-key attributes are not transitively dependent on the primary key.
BCNF: Every determinant is a candidate key.
24
🔷 Denormalization and its use cases
What is Denormalization ?
Denormalization involves combining tables to reduce the number of joins required
in queries. It's used to improve read performance, simplify queries, and optimize
data retrieval, especially in read-heavy applications or reporting systems.
Day 4
🔷 Advanced Topics and Best Practices
Advanced Topics in DBMS
Indexing and Query Optimization
Performance Tuning
NoSQL Databases: Introduction and Comparison with SQL
Use cases for NoSQL (Document, Key-Value, Column-Family, Graph
Databases)
25
🔷 Indexing and Query Optimization
What is Indexing ?
Indexing involves creating data structures that improve the speed of data retrieval
operations on a database table. Indexes are like a table of contents in a book,
making it faster to find specific information.
26
🔷 Performance Tuning
What is Performance Tuning ?
Performance tuning involves optimizing various aspects of a system to improve its
overall performance. In the context of databases, this includes tasks such as
optimizing queries, indexing, database schema design, and hardware configuration
to enhance data retrieval speed, throughput, and response times.
It aims to ensure that the system can handle increasing workloads efficiently while
maintaining acceptable performance levels.
27
🔷 NoSQL Databases: Introduction and Comparison
with SQL
NoSQL databases (Not Only SQL) are a category of databases that are designed to
handle large volumes of unstructured or semi-structured data, providing flexibility
and scalability that traditional SQL databases may struggle with. Here's an
introduction to NoSQL databases and a comparison with SQL databases:
28
Comparison with SQL Databases:
1. Data Model:
SQL Databases: Relational databases with structured data organized in
tables with rows and columns.
NoSQL Databases: Flexible data models, including document, key-value,
columnar, and graph structures.
2. Schema:
SQL Databases: Require predefined schemas with fixed structures.
NoSQL Databases: Support dynamic or flexible schemas, allowing for easy
adaptation to changing data requirements.
3. Scalability:
SQL Databases: Scale vertically (upgrading hardware) or through
replication and sharding techniques.
NoSQL Databases: Scale horizontally by distributing data across multiple
nodes or servers.
4. Query Language:
SQL Databases: Use SQL (Structured Query Language) for querying and
manipulating data.
NoSQL Databases: Each type of NoSQL database may have its query
language or API tailored to its specific data model.
5. Consistency:
SQL Databases: Typically provide strong consistency guarantees (ACID
properties).
NoSQL Databases: Offer various consistency models, including eventual
consistency, depending on the database type and configuration.
6. Use Cases:
SQL Databases: Well-suited for applications with structured data and
complex queries, such as transactional systems and reporting applications.
NoSQL Databases: Ideal for applications requiring flexibility, scalability, and
high performance, such as web applications, real-time analytics, and IoT
platforms.
29
🔷 Use cases for NoSQL (Document, Key-Value,
Column-Family, Graph Databases)
Each type of NoSQL database has its own strengths and ideal use cases:
1. Document Databases:
Use Case: Document databases are suitable for scenarios where flexibility
and scalability are essential, such as content management systems, e-
commerce platforms, and real-time analytics. They excel in applications
that require storing semi-structured or unstructured data, like JSON or XML
documents, as they allow for storing varying structures within the same
collection.
2. Key-Value Stores:
Use Case: Key-value stores are great for caching, session storage, and real-
time analytics. They're simple and efficient for storing and retrieving data
with a simple key lookup. Commonly used in distributed systems for high-
speed data retrieval and storage, key-value stores are ideal for scenarios
where the structure of the data is simple and access patterns are
straightforward.
30
3. Column-Family Databases:
UseTitll Case: Column-family databases are well-suited for applications that
require massive scalability and handle large amounts of data with high write
throughput, such as time series data, logging, and analytics. They excel in
scenarios where data is stored in columns rather than rows and where data
is accessed primarily by column subsets, allowing for efficient read and
write operations.
4. Graph Databases:
Use Case: Graph databases are ideal for applications dealing with highly
interconnected data, such as social networks, recommendation engines,
fraud detection, and network management. They excel at representing and
querying complex relationships between entities, enabling efficient
traversal of relationships and graph-based algorithms for analysis.
31
Day 5-6
🔷 Practice
Database Creation
Table Creation
Writing Complex Queries
Stored Procedure, Trigger, Functions
Interview Questions
32
Thank
You