Database Management System
Database Management System
A DBMS is a software system that enables users to define, create, maintain, and control
access to the database. It serves as an interface between the database and its end-users or
application programs, ensuring that data is consistently organized and remains easily
accessible.
The diagram illustrates the major components of a DBMS and their interactions. Here’s a
breakdown of each component and its role:
1. DDL Compiler:
- Function: Processes schema definitions specified in the Data Definition Language (DDL)
and stores the descriptions (metadata) in the DBMS catalog.
4. Query Compiler:
- Function: Validates the correctness of the query syntax and names of files/data elements,
compiling them into an internal form.
5. Query Optimizer:
- Function: Optimizes the query by rearranging and reordering operations, eliminating
redundancies, and using the best algorithms and indexes. It generates executable code for
the query and makes calls to the runtime processor.
6. Precompiler:
- Function: Extracts DML commands from application programs and sends them to the
DML compiler.
7. DML Compiler:
- Function: Compiles DML commands into object code for database access.
9. Canned Transactions:
- Function: Predefined transactions created by linking the compiled object codes of DML
commands and the rest of the application program. They include executable code with
runtime parameters.
Three Schema Architecture: The goal of the three-schema architecture is to separate user
applications from the physical database, providing a clear abstraction at different levels. This
helps in managing the complexity and enhances data independence. Schemas in this
architecture are defined at three levels:
- Internal Level
- Conceptual Level
- Each external schema describes the part of the database of interest to a specific user group.
- Typically implemented using a representational data model based on an external schema design.
2. Maintains Consistency:
- Helps maintain the accuracy and consistency of data within the database.
- Example: In a table of Enrollments that references a table of Students, an enrollment
should not exist if the student does not exist. This prevents inconsistencies like having an
enrollment for a non-existent student.
Example:
- `Employees` table:
- `EmployeeID` (Primary Key)
- `Name`
- `DepartmentID` (Foreign Key)
- `Departments` table:
- `DepartmentID` (Primary Key)
- `DepartmentName`
Scenario:
1. Adding Records:
- When adding a new employee, the `DepartmentID` in the `Employees` table must match
an existing `DepartmentID` in the `Departments` table.
- This ensures that the new employee is assigned to a valid department.
2. Deleting Records:
- If a department is deleted from the `Departments` table, all employees in that
department must be reassigned or deleted.
- This prevents the scenario where employees reference a non-existent department.
3. Updating Records:
- If the `DepartmentID` of a department changes, all related `DepartmentID` fields in the
`Employees` table must be updated to reflect this change.
- This maintains the consistency of the relationship between employees and departments.
By enforcing referential integrity, the database ensures that the relationships between
tables are valid and that data remains accurate and meaningful.
- Database Designers:
- Identify data to be stored and organize it effectively.
- Interact with different user groups to understand their requirements.
- Develop database views that cater to the needs of various user groups.
- End Users:
- Casual End Users:
- Occasional users needing varied information.
- Typically middle- or high-level managers.
- Use query language to specify requests.
- Stand-alone Users:
- Maintain personal databases using user-friendly program packages.
- Example: Users of tax packages for financial data storage.
- Tool Developers:
- Design and implement tools for database modeling, system design, and performance
enhancement.
Data Model A data model is a collection of concepts that can be used to describe the
structure of a database.
- Provide concepts that are close to the way many users perceive data.
- Use concepts such as entities, attributes, and relationships to describe the database structure.
- Offer concepts that are easily understood by end users but are not too far removed from the
actual data organization in computer storage.
- Hide many details of data storage on disk but can be directly implemented on a computer system.
- Include the relational data model and legacy data models like the network and hierarchical
models.
- Represent data using record structures and are sometimes referred to as record-based data
models.
- Describe the details of how data is stored on computer storage media, typically magnetic disks.
- Explain how data is stored as files on the computer, including information on record formats,
record orderings, and access paths.
6. Discuss different types of update operations on relational database. Explain how the basic
operations deal with constraint violation.
Types of Update Operations on Relational Database:
Insert Operation:
o Inserts one or more new tuples into a relation.
o Can violate four types of constraints:
1. Domain Constraints: Violation occurs if an attribute value is not of
the appropriate data type.
2. Key Constraints: Violation occurs if a key value in the new tuple
already exists in another tuple.
3. Entity Integrity: Violation occurs if any part of the primary key of the
new tuple is NULL.
4. Referential Integrity: Violation occurs if a foreign key value refers to
a non-existent tuple in the referenced relation.
o Examples:
1. Insertion with NULL primary key → Violates entity integrity
constraint.
2. Insertion with duplicate primary key → Violates key constraint.
3. Insertion with foreign key value not in referenced table → Violates
referential integrity constraint.
4. Insertion satisfying all constraints → Acceptable.
Delete Operation:
o Deletes tuples from a relation based on a specified condition.
o Can violate referential integrity if the deleted tuple is referenced by foreign
keys from other tuples.
o Examples:
1. Deletion of a tuple not referenced by others → Acceptable.
2. Deletion of a tuple referenced by others → Violates referential
integrity.
3. Deletion of a tuple referenced by multiple relations → Violates
referential integrity.
o Options if deletion causes a violation:
1. Restrict: Reject the deletion.
2. Cascade: Delete tuples that reference the deleted tuple.
3. Set Null or Set Default: Modify the referencing attribute values to
NULL or a default valid tuple.
Update Operation:
o Changes values of one or more attributes in existing tuples.
o Requires specifying a condition to select the tuples to be modified.
o Examples:
1. Updating non-key attribute → Acceptable if it does not violate any
constraints.
2. Updating foreign key to an invalid value → Violates referential
integrity.
3. Updating primary key to a duplicate value → Violates primary key and
referential integrity constraints.
o Constraints checked during update:
1. New value must be of the correct data type and domain.
2. Must not violate primary key or referential integrity constraints.
7. Explain different types of attributes in ER model with example.
Types of Attributes in ER Model:
- Composite Attribute:
- Attributes that can be divided into smaller sub-parts, which represent more basic
attributes with independent meanings.
- Example: `Name` can be divided into `First Name` and `Last Name`.
- Single-valued Attribute:
- Attributes that hold a single value for each entity instance.
- Example: `Date of Birth`.
- Multi-valued Attribute:
- Attributes that can hold multiple values for each entity instance.
- Example: `Phone Numbers` (an entity can have multiple phone numbers).
- Derived Attribute:
- Attributes whose values can be derived from other attributes.
- Example: `Age` can be derived from the `Date of Birth`.
- Stored Attribute:
- Attributes that are stored in the database.
- Example: `Date of Birth`, `Address`.
- Key Attribute:
- Attributes that uniquely identify an entity in an entity set.
- Example: `Employee ID` in an `Employee` entity set.
- Non-key Attribute:
- Attributes that do not participate in the uniqueness of an entity.
- Example: `Employee Name`, `Address` in an `Employee` entity set.
Examples:
1. Employee Entity:
- Simple Attribute: `SSN`
- Composite Attribute: `Name` (sub-attributes: `First Name`, `Last Name`)
- Single-valued Attribute: `Date of Birth`
- Multi-valued Attribute: `Phone Numbers`
- Derived Attribute: `Age` (derived from `Date of Birth`)
- Stored Attribute: `Date of Birth`, `Address`
- Key Attribute: `Employee ID`
- Non-key Attribute: `Employee Name`, `Address`
2. Student Entity:
- Simple Attribute: `Student ID`
- Composite Attribute: `Address` (sub-attributes: `Street`, `City`, `State`, `Zip Code`)
- Single-valued Attribute: `Date of Enrollment`
- Multi-valued Attribute: `Courses Enrolled`
- Derived Attribute: `Total Credits` (derived from `Courses Enrolled`)
- Stored Attribute: `Date of Birth`, `Address`
- Key Attribute: `Student ID`
- Non-key Attribute: `Student Name`, `Email`
8. Explain conceptual model (ER) to relational model mapping algorithm with example.
9. Explain relational model concepts schema, instance, primary key, super key, candidate
keyand weak entity
Relational Model Concepts:
1. Schema:
- Definition: Structure of the database at the logical level.
- Example: `Student(SID, Name, DateOfBirth, Address)`
2. Instance:
- Definition: Actual data in the database at a given time.
- Example:
```
| SID | Name | DateOfBirth | Address |
|------|------------|-------------|-----------------|
| 101 | John Doe | 2000-01-01 | 123 Elm St. |
| 102 | Jane Smith | 1999-05-15 | 456 Maple Ave. |
```
3. Primary Key:
- Definition: Unique identifier for a tuple in a table.
- Example: `SID` in the `Student` table.
4. Super Key:
- Definition: Set of attributes that uniquely identify a tuple.
- Example: `{SID}` and `{SID, Name}` in the `Student` table.
5. Candidate Key:
- Definition: Minimal super key; no subset can uniquely identify a tuple.
- Example: `SID` and potentially `Email` if unique in the `Student` table.
6. Weak Entity:
- Definition: Entity that cannot be uniquely identified by its own attributes alone; relies on
a strong entity.
- Example: `Dependent(DID, DependentName, EmployeeID)` where `DID` and `EmployeeID`
together uniquely identify a dependent.
These concepts help ensure data integrity, consistency, and efficient data management in a
relational database.
Schema:
- Definition: The overall structure of a database defined at the logical level. It includes the
definitions of tables, fields, and the relationships between them.
- Example: A `Student` schema may include the following structure:
```
Student(SID, Name, DateOfBirth, Address)
```
Instance:
- Definition: The actual content of the database at a particular point in time. It is the
collection of data stored in the database.
- Example: An instance of the `Student` table might include:
```
| SID | Name | DateOfBirth | Address |
|------|------------|-------------|-----------------|
| 101 | John Doe | 2000-01-01 | 123 Elm St. |
| 102 | Jane Smith | 1999-05-15 | 456 Maple Ave. |
```
Canned Transaction:
- Definition: Predefined, structured transactions designed to be executed frequently with
minimal input from the user. They are typically used for routine tasks and have been
carefully programmed and tested.
- Example: A bank teller using a transaction to check account balances or post withdrawals
and deposits.
Data Model:
- Definition: A collection of concepts that can be used to describe the structure of a
database, including data types, relationships, and constraints. It provides the necessary
means to model real-world scenarios in a database.
- Example: The Relational Data Model, which represents data in tables (relations) with rows
(tuples) and columns (attributes). Other examples include the Entity-Relationship Model and
the Object-Oriented Data Model.
These concepts are foundational in database design and management, helping to define,
organize, and manipulate data efficiently and effectively.