DBMS - NOTES - (Selected Topics)
DBMS - NOTES - (Selected Topics)
Definition
Types of DBMS
1. Hierarchical DBMS
2. Network DBMS
o Stores data in tables with rows and columns using structured query
language (SQL).
Advantages of DBMS
Disadvantages of DBMS
--------------------------------------------------------------------------------------------------------------
Definition
A Flat File System is a simple database system that stores data in a plain text format,
where records are separated by delimiters (e.g., commas, tabs, or new lines). Each file
typically contains a single table with no structured relationships between records.
� Simplicity – Easy to create and use without requiring complex database software.
� Lightweight – Requires minimal system resources, making it suitable for small-scale
applications.
� Portability – Can be easily transferred between different systems without
compatibility issues.
� Fast Access for Small Data – Works efficiently for small datasets with simple
operations.
� No Need for Specialized Software – Can be accessed using basic text editors or
spreadsheet programs like Microsoft Excel.
Disadvantages of Flat File System
� Data Redundancy – Repeated storage of the same data leads to increased storage
usage.
� Lack of Relationships – No support for relational links between records, making data
management difficult.
� Limited Scalability – Not suitable for handling large amounts of data efficiently.
� Slow Search and Retrieval – Searching for specific data can be slow since there are
no indexing mechanisms.
� Data Integrity Issues – Ensuring data consistency is challenging due to the absence
of constraints like primary keys or foreign keys.
3. ER Diagrams
Definition
Components of ER Diagrams
o Types:
o Types:
o Types:
Example ER Diagram
Disadvantages of ER Diagrams
Keys in SQL are used to identify and maintain relationships between records in a
database. They help enforce uniqueness, integrity, and consistency of data.
1. Primary Key �
• A table can have only one primary key (which may consist of a single or multiple
columns).
Example:
2. Candidate Key �
• A table can have multiple candidate keys, but only one can be chosen as the
primary key.
Example:
• In a Students table, both StudentID and Email can be candidate keys because
they uniquely identify a student.
3. Super Key �
• A super key is any set of attributes that can uniquely identify a record.
Example:
• Ensures referential integrity (i.e., prevents invalid data from being inserted).
Example:
5. Unique Key �
• Unlike Primary Key, it can contain NULL values (but must still be unique).
Example:
6. Composite Key �
Example:
(In this case, OrderID alone is not unique, but the combination of OrderID and
ProductID is.)
7. Alternate Key �
Example:
8. Surrogate Key �
Example:
(Here, CustomerID is a surrogate key generated automatically.)
Summary Table
Who is a DBA?
c. Data Security & Access Control – Manages user permissions and protects data
from unauthorized access.
d. Backup & Recovery – Ensures regular backups and disaster recovery planning.
g. Data Integrity & Consistency – Ensures ACID compliance and prevents data
corruption.
h. Scalability & High Availability – Manages replication and clustering for large-
scale databases.
Types of DBAs:
Conclusion
A DBA ensures databases are secure, optimized, and always available, playing a crucial
role in IT infrastructure.
6. Relational Algebra
Definition:
Basic Operations:
f. Set Difference (−) → Finds rows in one table but not in another.
g. Join (⋈) → Merges two tables based on a common attribute (foreign key).
Conclusion:
Relational Algebra forms the theoretical backbone of SQL queries and helps in
understanding data retrieval operations efficiently.
Definition:
Types of Normalization
• Each column should have atomic values (no multiple values in a single cell).
� After 1NF
• Achieves 1NF.
• Ensures that non-key attributes depend on the whole primary key, not just a
part of it.
1. Students Table:
| StudentID | StudentName |
|-----------|------------|
| 101 | John |
| 102 | Emma |
2. Courses Table:
| CourseID | CourseName |
|----------|------------|
| C001 | DBMS |
| C002 | OS |
• Achieves 2NF.
1. Students Table:
| StudentID | Name | DepartmentID |
|-----------|-------|-------------|
| 101 | John | D001 |
| 102 | Emma | D002 |
2. Departments Table:
| DepartmentID | DepartmentName |
|-------------|-------------------|
| D001 | Computer Science |
| D002 | Mathematics |
1. Professors Table:
| ProfessorID | CourseID |
|------------|----------|
| P101 | C001 |
| P102 | C002 |
2. Classroom Table:
| CourseID | Classroom |
|----------|-----------|
| C001 | Room 1 |
| C002 | Room 2 |
1. Employee-Skills Table:
| EmployeeID | Skill |
|-----------|--------|
| 201 | Python |
| 201 | Java |
2. Employee-Languages Table:
| EmployeeID | Language |
|-----------|---------|
| 201 | English |
| 201 | Hindi |
1. Projects Table:
| ProjectID | EmployeeID |
|----------|------------|
| P01 | E101 |
| P01 | E102 |
| P02 | E101 |
2. Roles Table:
| EmployeeID | Role |
|-----------|---------|
| E101 | Developer |
| E102 | Tester |
Conclusion
8. Generalization
Definition:
Generalization is a bottom-up approach in database design where multiple specific
entities with common attributes are merged into a single generalized entity
(superclass).
Example:
Key Points:
Conclusion:
9. Specialization
Definition:
Example:
Key Points:
Conclusion:
This architecture separates concerns, improves data independence, and enhances security
& usability in databases.
Explana�on:
Definition:
Data Independence refers to the ability to modify the schema at one level without
affecting the schema at the next higher level. It helps in maintaining flexibility and
reducing dependency between database structure and applications.
Key Benefits:
Conclusion:
12. Aggregation
Definition:
Example:
• Relationships:
� Aggregation Representation:
Instead of creating separate relationships, we treat "Enrollment" as an abstract entity
and form a new relationship with Instructor.
Key Points:
� Simplifies complex relationships in ER diagrams.
� Enhances database structure by reducing redundancy.
� Represents higher-level relationships efficiently.
Conclusion:
Definition:
Integrity constraints are rules applied to maintain the accuracy, consistency, and
reliability of data in a database.
2. Entity Integrity → Ensures every table has a primary key, and it cannot be NULL.
3. Referential Integrity → Ensures foreign key values must match primary key
values in the referenced table.
4. Key Constraint → Ensures that a primary key is unique for each row.
Conclusion:
Integrity constraints prevent invalid data entry, ensuring data consistency and
correctness in the database.
a. Referential Integrity
Definition:
Referential Integrity ensures that a foreign key in one table always refers to a valid
primary key in another table, preventing orphan records.
Example:
• Students Table:
• Enrollment Table:
Key Points:
Conclusion:
Definition:
Domain Integrity ensures that the values in a column follow a specific data type, format,
or range, preventing invalid data entry.
Example:
• Employee Table:
Key Points:
� Ensures values match the expected data type (e.g., Age must be an integer).
� Restricts values to valid ranges (e.g., Age ≥ 18).
� Enforced using CHECK, NOT NULL, UNIQUE, and data types in SQL.
Conclusion:
Definition:
Data Integrity ensures the accuracy, consistency, and reliability of data stored in a
database. It prevents unauthorized changes, duplication, and data corruption.
2. Entity Integrity → Ensures every table has a primary key, and it cannot be
NULL.
Key Benefits:
Conclusion:
Data Integrity is crucial for reliable databases, ensuring stored data remains valid,
accurate, and secure over time.
15. Instance
Definition:
Example:
• The current rows (actual data) represent the Instance at that moment.
Key Points:
Conclusion:
An Instance is the real-time data in a database, while the Schema defines the
structure.
16. Attributes
Definition:
Example:
2. Composite Attribute → Can be split into sub-parts (e.g., Name → First Name,
Last Name).
3. Derived Attribute → Derived from other attributes (e.g., Age from Date of
Birth).
Key Points:
Conclusion:
Attributes store specific details about an entity, making data structured and
meaningful.
2. End Users
3. Application Programmers
4. System Analysts
� Design database structure and decide how data is stored and accessed.
� Example: A business analyst defining data flow for an e-commerce app.
5. Database Designers
6. Sophisticated Users
7. Naïve Users
Conclusion:
Different users interact with databases based on their roles and expertise, ensuring
smooth operation and accessibility.
Definition:
A Data Model defines how data is organized, stored, and managed in a database. It
provides a structured framework for database design.
1. Hierarchical Model �
2. Network Model �
5. Object-Oriented Model 🏛🏛
Conclusion:
Data Models help in structuring databases, ensuring efficient data storage &
retrieval.
Definition:
The Hierarchical Data Model organizes data in a tree-like structure, where each
record has one parent and multiple children (one-to-many relationship).
Example:
• University Database
o University (Parent)
Key Features:
Advantages:
Disadvantages:
Conclusion:
The Hierarchical Model is efficient for structured data but not suitable for complex
relationships.
Definition:
The Network Data Model organizes data using a graph structure, allowing many-to-
many relationships through multiple parent-child links.
Example:
• University Database
Key Features:
Advantages:
Disadvantages:
Conclusion:
The Network Model is more flexible than the Hierarchical Model, making it suitable
for complex relationships like banking and airline systems.
SQL TOPICS :
1. SQL Commands
Definition:
SQL commands are instructions used to interact with a database, such as creating,
modifying, retrieving, and deleting data.
Conclusion:
Definition:
A Clause in SQL is a part of a query that helps filter, sort, or limit data retrieval.
Clauses are used with SQL commands like SELECT, INSERT, UPDATE, and DELETE.
SQL clauses help refine queries, making data retrieval efficient and meaningful.
3. Transaction
Definition:
If any step fails (e.g., system crash), the transaction is rolled back, preventing data
inconsistency.
-------------------------------------------------------------------------------------------
States of a Transaction
• Database must remain in a valid state before & after the transaction.
• � Example: Total money in accounts should remain the same before & after
a transfer.
• � Example: Two people booking the last movie ticket should not both
succeed.
Conclusion:
4. SQL Join
Definition:
A JOIN in SQL is used to combine rows from two or more tables based on a related
column (like a foreign key).
2 LEFT JOIN (LEFT OUTER JOIN) – Returns all records from the left table and
matching records from the right table.
3 RIGHT JOIN (RIGHT OUTER JOIN) – Returns all records from the right table and
matching records from the left table.
4 FULL JOIN (FULL OUTER JOIN) – Returns all records when there is a match in
either table.
5 CROSS JOIN – Returns the Cartesian product of both tables (all possible
combinations).