Ajay Unit 2 DBMS
Ajay Unit 2 DBMS
Schema
A schema is the blueprint or architecture of a database that defines how data is organized and
structured. It outlines the tables, fields, relationships, constraints, and other elements of the database.
The schema serves as a map or guide for how the database is built and how data is stored, organized,
and manipulated.
Types of Schemas:
1. Physical Schema: Describes how data is stored physically on the storage devices. It
includes file structures, indexes, and storage methods.
2. Logical Schema: Defines the logical structure of the database, including tables, views,
and relationships between tables. It is independent of physical considerations.
3. External Schema: Also known as user views, it defines how individual users see the
data. Each user can have a different view of the database tailored to their needs.
Question-2-What is Database independence and why is it important? What is difference between
logical and physical data independence?
Database Independence:
Database independence refers to the capacity of a database system to change its schema at one level
without requiring changes to the schema at the next higher level. This concept is critical in the
architecture of database systems, which typically follows a three-level schema architecture: the
internal level (physical), the conceptual level (logical), and the external level (views).
Importance of Database Independence:
1. Flexibility: Database independence allows the structure of the database to be modified without
affecting the application programs that access the data. This flexibility is crucial for adapting
to changing business requirements.
2. Maintenance: It simplifies database maintenance and evolution. Changes in storage structures,
indexing, or hardware can be made without modifying application code.
3. Improved Security: By abstracting the physical and logical details, database independence
helps in implementing security policies effectively. Sensitive data can be shielded from
unauthorized access by controlling what is visible at different schema levels.
4. Data Integrity: Ensures consistency and integrity of data as the higher-level schemas (logical
and external) remain unaffected by changes at the lower levels (physical).
Difference between Logical and Physical Data Independence:
1. Logical Data Independence:
1) Definition: The ability to change the conceptual schema (logical level) without
affecting the external schema or application programs.
2) Example Changes: Adding or removing entities, attributes, or relationships in the
logical schema.
3) Impact: Changes in the logical schema should not necessitate changes in application
programs or user views.
4) Importance: Ensures that changes to the structure of the database (e.g., adding a new
field to a table) do not require rewriting application programs that access the data.
Mapping
Mapping refers to the process of transforming data between different levels of abstraction within the
database. It involves converting data from one schema level to another, ensuring that data remains
consistent and accurate across different views and storage formats.
Types of Mappings:
1. External-Conceptual Mapping: Translates data between user views (external schemas)
and the logical structure (conceptual schema). It ensures that changes in user
requirements do not affect the logical schema.
2. Conceptual-Internal Mapping: Translates data between the logical structure (conceptual
schema) and the physical storage (internal schema). It ensures that changes in physical
storage do not affect the logical schema.
Instance
An instance is a specific snapshot or state of the data in the database at a particular moment in
time. While a schema defines the structure of the database, an instance refers to the actual data
that conforms to this structure. Instances change frequently as data is inserted, updated, or
deleted.
Question-5-Explain the DBMS architecture with neat & clean diagram.
Answer-The architecture of a Database Management System (DBMS) is typically divided into three
levels: the external level, the conceptual level, and the internal level. This three-level architecture is
designed to separate the user's view of the database from the physical structure of the database,
ensuring data abstraction and independence.
1. External Level (User View)
This level represents how data is viewed by individual users or specific user groups. Each external
view is tailored to the needs of different users, hiding the rest of the database from them. Users
interact with the database using these views.
2. Conceptual Level (Logical View)
This level provides a unified and comprehensive view of the entire database, independent of the
physical level. It represents all entities, their attributes, and their relationships. The conceptual
schema defines the logical structure of the entire database.
3. Internal Level (Physical View)
This level deals with the physical storage of data on the storage medium. It describes how data is
actually stored, the data structures, indexes, and the access paths. The internal schema defines the
physical storage structure of the database.
DBMS Architecture Diagram:
Here’s a diagram illustrating the three-level DBMS architecture:
sql
Copy code
+-------------------+ +--------------------------+
| External Level | <--- User Views ---- | External Schemas (Views) |
+-------------------+ +--------------------------+
|
V
+-------------------+ +--------------------+
| Conceptual Level | <--- Logical View -- | Conceptual Schema |
+-------------------+ +--------------------+
|
V
+-------------------+ +------------------+
| Internal Level | <--- Physical View - | Internal Schema |
+-------------------+ +------------------+
Schema:
A schema is the overall logical design or structure of a database. It defines how data is
organized, including the tables, fields, relationships, constraints, and other elements. It acts as
a blueprint that outlines the entire database's structure.
1) Scope: The schema covers the entire database, providing a comprehensive view of all
data entities and their relationships.
2) Types: There are different levels of schema in a database system:
3) Physical Schema: Details how data is physically stored on storage devices.
4) Logical Schema: Describes the logical structure of the entire database, including tables,
views, and relationships.
5) External Schema: Defines how individual users or user groups view the data, also
known as user views.
Subschema:
A subschema is a subset of the schema that provides a specific view of the database tailored to the
needs of particular users or applications. It includes only a portion of the database, focusing on the
relevant entities and relationships.
1. Scope: The subschema is limited to specific parts of the database, providing a more
focused view for certain operations or user roles.
2. Purpose: Subschemas are used to provide data security, simplifying user interactions by
showing only relevant data, and ensuring that users have access only to the data they
need.
Question-6-. Explain the difference between Logical and Physical data independence.
Answer-Logical and physical data independence are important concepts in database management
that help maintain the stability and flexibility of a database system. They refer to the capacity of a
database system to change its schema at different levels without affecting other levels.
Logical Data Independence
1. Logical data independence refers to the capacity to change the conceptual schema (logical
structure of the database) without having to alter the external schema or application programs.
This means modifications at the logical level, such as adding, deleting, or changing attributes
or entities, do not affect how users interact with the database or the application programs that
rely on it.
Physical Data Independence
2. Physical data independence refers to the ability to change the internal schema (physical
storage of data) without having to alter the conceptual schema or external schema. This means
changes to how data is stored on the hardware, such as using different storage devices,
changing file structures, or using different indexing methods, do not affect the logical
structure of the database or how users interact with the data.
Key Differences:
Scope of Changes:
3. Logical Data Independence: Involves changes to the logical structure (conceptual schema)
such as tables, columns, and relationships.
4. Physical Data Independence: Involves changes to the physical storage mechanisms (internal
schema) such as file structures, indexes, and storage devices.
Impact on Schemas:
1. Logical Data Independence: Changes at the conceptual level should not affect the external
schemas or the user interfaces.
2. Physical Data Independence: Changes at the internal level should not affect the conceptual
schema or the application programs.
Examples of Changes:
1. Logical Data Independence: Adding or removing attributes, changing relationships between
tables.
2. Physical Data Independence: Changing storage formats, indexing methods, or physical data
structures.
Ease of Implementation:
1. Logical Data Independence: Typically more challenging to achieve because changes often
affect the way data is logically related and organized.
2. Physical Data Independence: Generally easier to implement since it deals with underlying
storage mechanisms without altering the logical view of the data.
Instance:
1. Definition: An instance is a specific state or snapshot of the data in the database at a particular
moment in time. While the schema defines the structure of the database, an instance is the actual data
that conforms to this structure.
Characteristics:
2. Dynamic: The data instance can change frequently as new data is inserted, updated, or deleted.
3. Concrete Data: It represents the actual stored data, whereas the schema is the blueprint.
Role in Database System:
1. Data Manipulation: Instances are the actual data manipulated through CRUD (Create, Read, Update,
Delete) operations. Queries and transactions operate on instances to retrieve or modify data.
2. Data Retrieval: When users query the database, they interact with instances to get current, accurate
data. The instance reflects the real-time state of the data, ensuring users have the latest information.
3. Consistency and Integrity: Database management systems (DBMS) ensure that instances remain
consistent and adhere to the rules defined by the schema, such as constraints and relationships. This
maintains data integrity and accuracy.
4. Snapshots and Backups: Instances can be used to create snapshots or backups of the database at
specific points in time. This is useful for recovery, auditing, and historical data analysis.
Question-7-Explain the three-schema architecture of a database management system. Why do we need mappings between
different schema levels?
Answer-The three-schema architecture of a database management system (DBMS) is a framework
that divides the database system into three levels of abstraction to separate the user's view from the
physical storage of data. This architecture helps achieve data independence, which is crucial for the
flexibility and maintainability of the database system. The three levels are:
1. External Level (User View)
1. The external level is the highest level of abstraction and represents how individual users or user groups view
the data. Each user has a customized view of the database tailored to their specific needs. These views are
known as external schemas or subschemas.
Characteristics:
2. Multiple external schemas can exist.
3. Each external schema describes a part of the database relevant to a particular user or group.
4. Provides data security by restricting access to specific parts of the database.
2. Conceptual Level (Logical View)
1. The conceptual level provides a unified and abstract view of the entire database, independent of how the data
is physically stored. This level describes the structure of the whole database for a community of users. The
conceptual schema defines the logical structure of the data, including the relationships, constraints, and
entities.
Characteristics:
2. Only one conceptual schema exists for the entire database.
3. Hides the physical details of data storage.
4. Ensures data consistency and integrity across different user views.
3. Internal Level (Physical View)
1. The internal level is the lowest level of abstraction and describes how the data is actually stored on the storage
medium. It includes details about the physical storage structures, access methods, and optimization strategies.
The internal schema defines the physical storage and access paths for the data.
Characteristics:
2. Only one internal schema exists for the database.
3. Manages the data storage and retrieval efficiency.
4. Handles the physical data structures, such as indexes and file organization.
Mappings between Different Schema Levels
1. Mappings between different schema levels are essential for maintaining data independence and ensuring the
integrity and consistency of the database. There are two primary types of mappings:
External-Conceptual Mapping:
2. Purpose: To translate the external schema to the conceptual schema and vice versa.
3. Function: Ensures that the user's view of the data (external schema) is consistent with the logical structure of
the data (conceptual schema). It maps the external queries and updates to the conceptual schema.
Conceptual-Internal Mapping:
1. Purpose: To translate the conceptual schema to the internal schema and vice versa.
2. Function: Ensures that changes in the physical storage of data do not affect the logical structure. It maps the
logical data model to the physical data storage structures, optimizing data retrieval and storage.
Why Mappings are Necessary
Data Independence: Mappings provide a layer of abstraction that allows changes at one level without affecting
the other levels. Logical data independence is achieved by the external-conceptual mapping, and physical data
independence is achieved by the conceptual-internal mapping.
Consistency and Integrity: Mappings ensure that different user views (external schemas) are consistent with
the overall database structure (conceptual schema) and that the logical data model is accurately represented in
the physical storage (internal schema).
Flexibility:
1. Mappings allow the database to adapt to changes in user requirements (external schema) and advancements in
storage technologies (internal schema) without significant disruptions.
Security:
By providing tailored external schemas, mappings help enforce security policies by restricting user access to specific
parts of the database while maintaining a consistent and secure logical structure.
Question-8-Discuss network data model taking suitable example. What are its advantages and disadvantages?
Answer-The network data model is one of the classic database models that organizes data using
records and relationships. Unlike the hierarchical model, which arranges data in a tree-like structure,
the network model allows more complex relationships between entities. It represents data as a
collection of records connected by links (pointers), forming a graph structure.
Example of Network Data Model
Consider a simple database for a university system where we have entities such as Students,
Courses, and Instructors. In the network model, these entities are represented as records, and the
relationships between them are represented by sets.
Entities:
Student (Student ID, Name, Major)
Course (Coursed, Course Name, Credits)
Instructor (Instructor ID, Name, Department)
Relationships:
Enrolment: A many-to-many relationship between Students and Courses.
Teaching: A many-to-many relationship between Instructors and Courses.
Here’s how this might be represented in a network data model:
Records:
STUDENT
StudentID: S1, Name: John Doe, Major: Computer Science
StudentID: S2, Name: Jane Smith, Major: Mathematics
COURSE
CourseID: C1, CourseName: Database Systems, Credits: 3
CourseID: C2, CourseName: Calculus, Credits: 4
INSTRUCTOR
InstructorID: I1, Name: Dr. Brown, Department: CS
InstructorID: I2, Name: Dr. Green, Department: Math
Sets (Relationships):
ENROLLMENT (Students to Courses)
S1 -> C1
S2 -> C1
S2 -> C2
TEACHING (Instructors to Courses)
I1 -> C1
I2 -> C2
Advantages of the Network Data Model
1) Flexibility in Modelling Relationships: The network model allows the representation of
more complex relationships, including many-to-many relationships, which is not
possible in a hierarchical model.
2) Efficiency: Navigation through records using pointers can be very efficient, especially
for queries that involve traversing relationships.
3) Data Integrity: Enforces referential integrity by maintaining consistent links between
records, ensuring that relationships are explicitly managed.
4) Performance: Provides high performance for certain types of queries, particularly those
involving traversal of relationships, because the use of pointers can reduce the need for
expensive join operations.
Disadvantages of the Network Data Model
1) Complexity: The schema can become very complex, especially as the number of
relationships increases, making the database harder to design, implement, and maintain.
2) Navigational DML: Data manipulation in the network model often requires a
navigational approach, which can be less intuitive and harder to write compared to
declarative query languages like SQL.
3) Lack of Ad Hoc Queries: The reliance on pointers and predefined paths can limit the
ability to perform ad hoc queries. Users need to know the structure of the database to
retrieve data effectively.