Dbms Unit 01
Dbms Unit 01
File System:
A file system is a method of storing and organizing files and their data. While it’s a fundamental part
of an operating system, it has several limitations when it comes to managing large amounts of data.
o Inconsistency: If data is duplicated, there is a risk that changes made to the data in
one file are not reflected in other files.
2. Data Isolation:
o Because data is stored in various files, it can be challenging to retrieve data from
multiple sources for analysis.
3. Data Integrity:
4. Access Control:
5. Atomicity Issues:
6. Concurrency Problems:
A DBMS is software that uses a standard method to store and organize data. It overcomes many of
the limitations of file systems by providing a systematic way to create, retrieve, update, and manage
data.
2. Data Isolation:
o Data is stored in tables that can be linked using relationships, making it easier to
retrieve data from multiple tables.
3. Data Integrity:
o Integrity constraints (like primary keys, foreign keys, and check constraints) ensure
the accuracy and consistency of the data.
4. Access Control:
o Ensures that all transactions are processed reliably and that the database remains
consistent in case of failures.
6. Concurrency Control:
Example:
• File System: Imagine a library where each book's information is stored separately by title,
author, and genre in different files. If the author’s name changes, updating every file is
cumbersome and prone to errors.
• DBMS: The same library’s data is stored in a DBMS with tables for books, authors, and
genres linked by relationships. Updating the author’s name in one place updates it
everywhere, maintaining consistency.
Advantages of DBMS
1. Data Independence:
o Logical Data Independence: Changes in the logical structure (like adding new fields)
do not affect application programs.
o Physical Data Independence: Changes in the physical storage of data do not affect
the DBMS's logical structure.
o Uses indexing, query optimization, and other techniques to retrieve data quickly,
even from large datasets.
o Security measures, such as user authentication and access control, protect data
from unauthorized access.
4. Data Administration:
o Centralized data management reduces redundancy, maintains consistency, and
simplifies data maintenance.
o Provides high-level interfaces and common functions, reducing the time and effort
required to develop applications.
Example:
• A university DBMS manages student records, course registrations, and grades. It ensures
that a student cannot register for a course without the prerequisite, maintains consistency
even if multiple administrators access the data simultaneously, and recovers data in case of
system failures.
Storage Data
2. File Manager:
o Manages the creation, deletion, reading, and writing of files within the DBMS.
3. Buffer Manager:
o Handles the transfer of data between disk storage and main memory, optimizing
performance.
4. Storage Hierarchy:
o Data is stored in a hierarchy from fast and expensive storage (like main memory and
cache) to slower and cheaper storage (like magnetic disks and tapes). This hierarchy
balances cost and performance.
Example:
• When a user queries a database, the buffer manager retrieves the required data from disk
storage to main memory, ensuring quick access. The disk space manager ensures that the
data is stored efficiently on the disk.
Queries
Query Processing:
1. Query Parser:
o Parses SQL commands, checking for syntax errors and converting the query into an
internal representation.
2. Query Optimizer:
o Determines the most efficient way to execute the query by considering different
execution plans and selecting the one with the lowest cost.
3. Query Executor:
o Executes the query using relational operators like selection, projection, and join.
o Manage data retrieval from disk to memory during query execution, ensuring
efficient data access.
Example:
• When a user runs an SQL query to find all students enrolled in a specific course, the query
parser validates the query syntax, the query optimizer finds the best way to access the data,
and the query executor retrieves and displays the results.
DBMS Structure
1. SQL Interface:
2. Query Optimizer:
3. Execution Engine:
5. Buffer Manager:
7. Concurrency Control:
o Ensures safe concurrent access to data by multiple users.
8. Transaction Manager:
9. Recovery Manager:
Example:
• When a banking system processes a transaction, the transaction manager ensures that the
transaction follows ACID properties, the concurrency control mechanism handles multiple
users accessing their accounts simultaneously, and the recovery manager ensures that all
transactions are properly logged for recovery in case of a system failure.
Types of Databases
1. Hierarchical Databases:
o Data is organized in a tree-like structure with a single root and multiple levels of
nested child records.
2. Network Databases:
3. Relational Databases:
o Data is stored in tables with rows and columns. Relationships are established
through foreign keys.
o Example: A customer and order database where customers and orders are linked by
customer IDs.
4. Key-Value Databases:
o Example: NoSQL databases like Redis, where user sessions are stored as key-value
pairs.
5. Object-Oriented Databases:
o Example: Multimedia databases storing images, videos, and audio files as objects.
6. XML Databases:
File Structures:
1. Heap Files:
o Unordered records are stored in pages. Suitable for small databases where searching
isn't intensive.
2. Sorted Files:
o Records are stored in a sorted order based on a key. Efficient for range queries.
3. Hashed Files:
o Records are distributed across buckets based on a hash function. Provides efficient
access for equality searches.
4. Indexes:
▪ B-trees: Balanced tree structure for efficient range and equality searches.
Data Models
Data models are essential frameworks for database design. They define the structure of a database,
the relationships among data elements, and the constraints that apply to the data. Let's explore
different types of data models in detail:
o Structure: Represents data in a tree-like structure, with a single root and multiple
levels of nested child records.
o Usage: Suitable for applications where data naturally forms a hierarchy, such as file
systems and XML documents.
o Usage: Suitable for complex relationships and scenarios requiring more flexibility
than the hierarchical model.
o Structure: Data is stored in tables (relations) consisting of rows (tuples) and columns
(attributes). Relationships among tables are established through foreign keys.
o Example: A customer and order database where customers and orders are linked by
customer IDs.
o Usage: Widely used in various applications, from small systems to large enterprise
applications.
o Advantages: Provides data independence, supports complex queries with SQL, and
ensures data integrity through constraints.
o Disadvantages: Performance issues with very large datasets and complex joins.
o Example: Multimedia databases storing images, videos, and audio files as objects
with properties and methods.
o Advantages: Supports complex data types and encapsulates both data and behavior.
o Advantages: Supports complex data types and inheritance while maintaining the
familiarity of relational models.
o Usage: Useful in the initial design phase to conceptualize and visualize the data
model.
o Disadvantages: More abstract and requires transformation into a logical model for
implementation.
1. Data Organization:
2. Simplification of Design:
o Simplifies the database design process by providing a clear blueprint. This helps
database designers and developers understand the structure and relationships of
the data.
o Enforces data integrity rules, ensuring that the data remains accurate and
consistent. This is crucial for maintaining the quality and reliability of the data.
4. Enhanced Communication:
o Defines data operations and constraints, supporting efficient data management. This
includes data retrieval, updates, and deletions, ensuring that the database performs
optimally.
6. Facilitation of Maintenance:
o Makes it easier to maintain and update the database. Provides a clear structure that
helps identify the impact of changes and ensures that updates are made
consistently.
Example:
Consider a company that needs to manage employee data. A well-designed data model ensures that:
• Employee records are stored consistently, with attributes like ID, name, position, and
department.
• Relationships between employees and departments are clearly defined, facilitating queries
like "Find all employees in a specific department."
• Data integrity is maintained, preventing duplicate records and ensuring accurate updates.
E-R Model: Entities, Attributes, and Entity Sets; Relationship and Relationship Set; Mapping
• Entity:
o Example: For a "Book" entity, attributes might include ISBN, title, author, and
publisher.
• Entity Set:
o Example: The entity set for "Books" includes all books in the library, each
represented with attributes like ISBN, title, and author.
• Relationship:
o Example: The relationship between a "Student" and a "Course" they are enrolled in
is a relationship. This relationship might be named "Enrolled."
• Relationship Set:
o Example: The "Enrolled" relationship set includes all pairs of students and courses,
indicating which students are enrolled in which courses.
• Descriptive Attributes:
Mapping Cardinalities
• Mapping Cardinalities specify the number of entities to which another entity can be
associated via a relationship set. Common mapping cardinalities include:
o One-to-One (1:1): Each entity in the first set is associated with at most one entity in
the second set, and vice versa.
▪ Example: Each employee has one unique employee ID, and each ID
corresponds to one employee.
o One-to-Many (1): Each entity in the first set can be associated with multiple entities
in the second set, but each entity in the second set is associated with at most one
entity in the first set.
▪ Example: A department has many employees, but each employee belongs to
one department.
o Many-to-One (N:1): Each entity in the first set is associated with at most one entity
in the second set, but each entity in the second set can be associated with multiple
entities in the first set.
o Many-to-Many (M): Entities in both sets can be associated with multiple entities in
the other set.
▪ Example: Students can enroll in multiple courses, and each course can have
multiple students enrolled.
Example:
Consider a university database with entities "Student" and "Course." The "Enrolled" relationship
represents the association between students and courses:
• Entity Set:
• Attributes:
• Relationship Set:
• Descriptive Attribute:
• Mapping Cardinalities:
o One-to-Many: One course can have many students enrolled, but each student can
enroll in many courses.