Dbms Unit Test Notes Till Unit 4
Dbms Unit Test Notes Till Unit 4
➢ Characteristics of Database
Overview of the Database Approach
The database approach is a modern way of managing data that replaces
traditional file-based systems. Unlike file systems, where each application
manages its own data separately, a database system stores data in a central
repository, allowing multiple users to access and share it efficiently. This
ensures consistency, reduces redundancy, and improves data management.
Key Characteristics
1. Self-Describing Nature (Metadata Storage)
A database system stores metadata—information about the database
structure, data types, and constraints—in a DBMS catalog. This allows the
DBMS to manage different applications (e.g., banking, university databases)
without modifying the system itself. In contrast, traditional file systems embed
data definitions within programs, making them less flexible.
2. Data Abstraction and Independence
In traditional file systems, changes to data structure require modifying all
dependent programs. In a DBMS, data structure is stored separately, ensuring
program-data independence. Users interact with a logical view of the data,
without worrying about storage details, thanks to data abstraction.
3. Multiple Views of Data
Different users require different views of the database:
• A student may see only their records.
• A professor may access course grades.
• An admin may manage all student data.
A DBMS allows customized views without affecting the actual database
structure.
4. Multi-User Access & Transaction Control
A multi-user DBMS allows multiple users to access and modify data
simultaneously while ensuring ACID properties:
• Atomicity – A transaction is either fully completed or not executed at all.
• Consistency – The database remains in a valid state before and after
transactions.
• Isolation – Transactions do not interfere with each other.
• Durability – Committed changes are permanently saved.
For example, when booking an airline seat, the DBMS ensures that only one
user secures a specific seat, preventing double booking.
Data Independency
Data independence is a property of a database management system by which
we can change the database schema at one level of the database system
without changing the database schema at the next higher level. In this article,
we will learn in full detail about data independence and will also see its types.
If you read it completely, you will understand it easily.
Types of Data Independence in DBMS
Data independence refers to the ability to modify a database schema at one
level without affecting other levels. It ensures flexibility and minimizes the
impact of changes on users and applications. There are two types of data
independence:
1. Logical Data Independence
• Definition: The ability to change the logical schema (conceptual level)
without affecting the external schema (user view level).
• Purpose: Keeps the user’s view of data unchanged even if modifications
are made at the conceptual level.
• Example:
o Adding a new column (e.g., “Email” in a student table) or deleting
an attribute (e.g., “Middle Name”) without affecting user
applications.
1. 1-Tier Architecture
• Definition: In 1-Tier Architecture, the client, database, and application
exist on the same machine. Users can directly access and manage data
without an external server.
• Example: A Microsoft Excel spreadsheet, where users enter, modify, and
store data on their local system without a separate database server.
Advantages:
✔ Simple setup requiring minimal configuration.
✔ Cost-effective as no additional hardware or servers are needed.
✔ Easy deployment and maintenance, making it suitable for small-scale
applications.
Disadvantages:
✖ Limited scalability, making it unsuitable for multi-user applications.
✖ Lower security, as all data is stored locally.
✖ Lack of centralized data management, leading to inconsistency across
multiple users.
2. 2-Tier Architecture (Client-Server Model)
• Definition: 2-Tier Architecture introduces a database server that
manages and processes requests from multiple client applications.
Clients use ODBC/JDBC APIs to interact with the database.
• Example: A Library Management System, where users access a desktop
application to search for books, issue returns, and manage transactions,
while a centralized database server stores and processes the data.
Advantages:
✔ Faster data access due to direct communication between the client and
database.
✔ Improved security by restricting unauthorized access to the database.
✔ Scalable, allowing multiple clients to connect to the same database.
✔ Easy deployment, making it an efficient model for schools, offices, and small
businesses.
Disadvantages:
✖ Increased network load, as all clients directly interact with the database.
✖ Performance bottlenecks, especially when multiple users send simultaneous
requests.
✖ Limited scalability compared to 3-Tier Architecture, as handling a large
number of users can become difficult.
3. 3-Tier Architecture (Application Layer Model)
• Definition: 3-Tier Architecture introduces an intermediate application
server between the client and database server. Instead of directly
communicating with the database, clients send requests to the
application server, which processes the request and interacts with the
database.
• Example: E-commerce platforms (Amazon, Flipkart), where users browse
products, add them to a cart, and place orders. The application server
handles user requests, processes payments, and retrieves data from the
database.
Advantages:
✔ Enhanced scalability, as application servers can distribute user requests
efficiently.
✔ Better security, as users do not have direct access to the database.
✔ Improved data integrity, since the application layer ensures that only valid
data is stored in the database.
✔ Load balancing, as processing is distributed across multiple servers.
Disadvantages:
✖ More complex implementation, requiring multiple servers and additional
maintenance.
✖ Increased latency, as requests must pass through an additional layer before
reaching the database.
✖ Higher cost, as it requires dedicated application servers and networking
infrastructure.
The Entity Relationship Model is a model for identifying entities (like student,
car or company) to be represented in the database and representation of how
those entities are related. The ER data model specifies enterprise schema that
represents the overall logical structure of a database graphically.
Symbols Used in ER Model
ER Model is used to model the logical view of the system from a data
perspective which consists of these symbols:
• Rectangles: Rectangles represent Entities in the ER Model.
• Ellipses: Ellipses represent Attributes in the ER Model.
• Diamond: Diamonds represent Relationships among Entities.
• Lines: Lines represent attributes to entities and entity sets with other
relationship types.
• Double Ellipse: Double Ellipses represent Multi-Valued Attributes.
• Double Rectangle: Double Rectangle represents a Weak Entity.
Components of ER Diagram
ER Model consists of Entities, Attributes, and Relationships among Entities in a
Database System.
Types of Attributes
1. Key Attribute
The attribute which uniquely identifies each entity in the entity set is called the
key attribute. For example, Roll_No will be unique for each student. In ER
diagram, the key attribute is represented by an oval with underlying lines.
2. Composite Attribute
An attribute composed of many other attributes is called a composite attribute.
For example, the Address attribute of the student Entity type consists of Street,
City, State, and Country. In ER diagram, the composite attribute is represented
by an oval comprising of ovals.
3. Multivalued Attribute
An attribute consisting of more than one value for a given entity. For example,
Phone_No (can be more than one for a given student). In ER diagram, a
multivalued attribute is represented by a double oval.
4. Derived Attribute
An attribute that can be derived from other attributes of the entity type is
known as a derived attribute. e.g.; Age (can be derived from DOB). In ER
diagram, the derived attribute is represented by a dashed oval.
➢ Cardinality and Participation in DBMS
In a Database Management System (DBMS), Cardinality and Participation
define the relationships between entities in an Entity-Relationship (ER) Model.
These concepts help in designing how data is structured and connected within
a database.
1. Cardinality
Cardinality refers to the number of instances of an entity that can be
associated with another entity in a relationship. It specifies how many times an
entity in one table can be related to entities in another table.
Types of Cardinality:
1. One-to-One (1:1)
o Each entity in Entity A is related to only one entity in Entity B, and
vice versa.
o Example: A country has one capital city, and each capital city
belongs to only one country.
o Representation:
2. One-to-Many (1:M)
o An entity in Entity A can be related to multiple entities in Entity B,
but each entity in Entity B is related to only one entity in Entity A.
o Example: A teacher can teach multiple students, but each student
is taught by only one teacher.
o Representation:
3. Many-to-Many (M:N)
o Multiple entities in Entity A can be related to multiple entities in
Entity B.
o Example: A student can enroll in multiple courses, and a course
can have multiple students.
o Representation:
2. Participation
Participation defines whether all instances of an entity must be involved in a
relationship or not. It determines if the relationship is mandatory or optional.
Types of Participation:
1. Total Participation
o Every entity in the set must be involved in the relationship.
o Example: Every employee in a company must be assigned to a
department.
o Representation: A double line between entity and relationship.
2. Partial Participation
o Some entities may not be involved in the relationship.
o Example: Not every student in a school is enrolled in a sports
team.
o Representation: A single line between entity and relationship.
➢ Extended Entity-Relationship (EER) Model: Generalization,
Specialization, and Aggregation
The Extended Entity-Relationship (EER) model is an enhancement of the
traditional Entity-Relationship (ER) model. It includes new concepts like
Generalization, Specialization, and Aggregation, which help in designing
complex database schemas.
1. Generalization
Generalization is the process of combining multiple lower-level entities into a
higher-level entity. It is a bottom-up approach, where common attributes
from different entities are grouped into a single superclass.
Example:
• Car and Bike are specific entities.
• Both share common attributes like engine number, company name, and
model.
• They can be generalized into a Vehicle entity.
2. Specialization
Specialization is the opposite of generalization. It is a top-down approach,
where a higher-level entity is divided into multiple lower-level entities based
on specific attributes.
Example:
• The Employee entity can be specialized into two sub-entities:
o Manager (having additional attributes like department managed).
o Technician (having additional attributes like skill set).
Diagram Representation:
3. Aggregation
Aggregation is the process of treating a relationship as an entity itself. It
allows relationships to participate in other relationships.
Example:
• A Professor guides Students in a Research Project.
• Instead of creating two separate relationships, the "Guides" relationship
can be treated as an entity, which then forms another relationship with
Funding.
Diagram Representation:
Unit 3
1. Overview of SQL
Structured Query Language (SQL) is a standardized, declarative language
designed for managing and manipulating relational databases. It allows users to
create, modify, query, and control access to data. SQL’s power lies in its ability
to work at a high level—specifying what data you need rather than how to
retrieve it. Key areas include:
SQL has evolved over decades and, while standards (like SQL-92, SQL:1999,
SQL:2016) exist, many implementations extend the core language to include
additional features.
CREATE:
Example:
Unit 3 1
ALTER: Modify an existing object (e.g., add or change a column).
Example:
Example:
TRUNCATE: Delete all data in a table quickly without logging individual row
deletions.
Integrity Constraints
These rules ensure data accuracy and consistency:
Key Constraints:
Domain Constraints:
Define the valid range, type, or format for a column’s data (e.g.,
INTEGER, VARCHAR(50)).
Referential Integrity:
Enforced using foreign keys, it ensures that a value in one table (child)
must match a primary key in another (parent).
Example:
Check Constraints:
Unit 3 2
Define a condition that must be true for each row in a table.
Example:
Example:
Example:
Example:
UPDATE Employees
SET Department = 'Marketing'
WHERE EmployeeID = 101;
Example:
Unit 3 3
DELETE FROM Employees
WHERE EmployeeID = 101;
Example:
Example:
EXCEPT (or MINUS): Returns records from one query that are not in the
other.
String Operations
SQL includes functions for manipulating text:
Concatenation:
Example:
Unit 3 4
SELECT FirstName || ' ' || LastName AS FullName FROM Employee
s;
Substring Extraction:
Example:
Case Conversion:
Example:
Example:
GROUP BY
Groups rows that share a common attribute so that aggregate functions can be
applied to each group:
Example:
HAVING
Unit 3 5
Filters groups created by GROUP BY based on aggregate conditions:
Example:
7. Views in SQL
A view is a virtual table defined by a SQL query. It simplifies complex queries
and can provide a layer of security by exposing only specific data.
Creating a View:
Example:
Using a View:
Example:
8. Joins in SQL
Joins combine rows from two or more tables based on a related column:
Example:
Unit 3 6
LEFT (OUTER) JOIN: Returns all rows from the left table and matched rows
from the right table; unmatched right table rows yield NULLs.
RIGHT (OUTER) JOIN: Returns all rows from the right table and matched
rows from the left.
FULL (OUTER) JOIN: Returns rows when there is a match in either left or
right table.
Self JOIN: A table is joined with itself to compare rows within the same
table.
Correlated Subqueries:
Subqueries that refer to columns from the outer query.
Example:
Unit 3 7
CTEs: Named temporary result sets defined with a WITH clause.
Example:
WITH DeptAvg AS (
SELECT DepartmentID, AVG(Salary) AS AvgSalary
FROM Employees
GROUP BY DepartmentID
)
SELECT e.FirstName, e.LastName, e.Salary, d.AvgSalary
FROM Employees e
JOIN DeptAvg d ON e.DepartmentID = d.DepartmentID
WHERE e.Salary > d.AvgSalary;
Types of Triggers:
Purpose:
Unit 3 8
VALUES (NEW.EmployeeID, 'INSERT', NOW());
END;
Unit 3 9