DBMS Mod 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

DBMS NOTES

Syllabus
Introduction to database Systems, advantages of database system over traditional
file system, Basic concepts & Definitions, Database users, Database Language,
Database System Architecture, Schemas, Sub Schemas, & Instances, database
constraints, 3-level database architecture, Data Abstraction, Data Independence,
Mappings, Structure, Components & functions of DBMS, Data models.

Entity relationship model, Components of ER model, Mapping E-R model to


Relational schema, Network and Object Oriented Data models. Relational Algebra,
Tuple & Domain Relational Calculus, Relational Query Languages: SQL and QBE.
Query processing and optimization: Evaluation of Relational Algebra Expressions,
Query optimization, Query cost estimation.

Database Design:-Database development life cycle (DDLC), Automated design tools,


Functional dependency and Decomposition, Join strategies, Dependency
Preservation & lossless Design, Normalization, Normal forms:1NF, 2NF,3NF, and
BCNF, Multi-valued Dependencies, 4NF & 5NF.

Transaction processing and concurrency control: Transaction concepts, properties of


transaction, concurrency control, locking and Timestamp methods for concurrency
control schemes. Database Recovery System, Types of Data Base failure & Types of
Database Recovery, Recovery techniques. Fundamental concepts of advanced
databases.
Storage Strategies: Detailed Storage Architecture, RAID

Introduction to Database Systems:


A database is a structured collection of data that is organized to support efficient
retrieval, storage, and management of information. Database systems play a crucial
role in modern information management, providing a structured and efficient way to
store and retrieve data.

DBMS NOTES 1
Advantages of Database Systems over Traditional File Systems:

1. Data Integrity: Database systems ensure data integrity by enforcing constraints


and relationships, preventing inconsistencies that can arise in flat file systems.

2. Data Independence: Changes in the structure of the database (schema) do not


affect the application programs using the data. This provides a level of
abstraction, reducing the impact of modifications.

3. Data Security: Database systems offer better security features, including


access control mechanisms, encryption, and authentication, ensuring that only
authorized users can access and modify data.

4. Concurrent Access: Multiple users can access the database simultaneously


without interfering with each other. Database systems manage concurrent
access through locking mechanisms.

5. Data Redundancy Reduction: Database systems minimize data redundancy by


storing data in a centralized manner, reducing storage requirements and
avoiding inconsistencies.

6. Query Language: Database systems use SQL (Structured Query Language), a


powerful language for querying and manipulating data. This standardized
language simplifies data retrieval and manipulation.

SQL Code Example:

-- Creating a simple "Students" table


CREATE TABLE Students (
StudentID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Age INT
);

-- Inserting data into the "Students" table


INSERT INTO Students (StudentID, FirstName, LastName, Age)
VALUES (1, 'John', 'Doe', 20),
(2, 'Jane', 'Smith', 22);

-- Retrieving data from the "Students" table


SELECT * FROM Students;

This example demonstrates the creation of a basic table, insertion of data, and a
simple query to retrieve all records from the "Students" table.

DBMS NOTES 2
Database Users:
1. Naive Users:

Description: Users with little or no technical expertise in database systems.

Interaction: They interact with the database through user-friendly


applications and may not be involved in complex database operations.

Example: Data entry clerks using a point-and-click interface.

2. Online Users:

Description: Users who interact with the database in real-time through


online applications or web interfaces.

Interaction: They perform transactions, queries, and updates through online


systems.

Example: Customers accessing an e-commerce website.

3. Sophisticated Users:

Description: Users with advanced knowledge of database systems.

Interaction: They directly write complex queries, design database


structures, and perform in-depth analysis.

Example: Business analysts, data scientists, or database developers.

4. Unsophisticated Users:

Description: Users who have some knowledge of databases but are not
experts.

Interaction: They may use pre-defined queries or reports and perform


routine operations.

Example: Middle-level managers generating standard reports.

5. Database Administrators (DBA):

Description: Professionals responsible for the management, design, and


security of the database system.

Functions:

Database Design: Designing the structure of the database, including


tables, relationships, and constraints.

DBMS NOTES 3
Data Security: Implementing security measures to control access and
protect sensitive information.

Performance Tuning: Optimizing the database for efficient data


retrieval and storage.

Backup and Recovery: Planning and implementing strategies for data


backup and recovery.

User Management: Managing user accounts, permissions, and roles.

Monitoring and Maintenance: Regularly monitoring the database


system for issues and performing maintenance tasks.

Troubleshooting: Identifying and resolving problems related to


database performance, connectivity, or data integrity.

Database Languages:
1. DDL (Data Definition Language):

Purpose: Defines and manages the structure of the database.

Basic Syntax:

CREATE : Used to create database objects such as tables, indexes, or


views.

CREATE TABLE TableName (


Column1 DataType,
Column2 DataType,
...
);

ALTER : Modifies the structure of an existing database object.

ALTER TABLE TableName


ADD ColumnName DataType;

DROP : Deletes a database object.

DROP TABLE TableName;

DBMS NOTES 4
2. DML (Data Manipulation Language):

Purpose: Manipulates the data stored in the database.

Basic Syntax:

SELECT : Retrieves data from one or more tables.

SELECT Column1, Column2


FROM TableName
WHERE Condition;

INSERT : Adds new records to a table.

INSERT INTO TableName (Column1, Column2)


VALUES (Value1, Value2);

UPDATE : Modifies existing records in a table.

UPDATE TableName
SET Column1 = NewValue
WHERE Condition;

DELETE : Removes records from a table.

DELETE FROM TableName


WHERE Condition;

3. DCL (Data Control Language):

Purpose: Manages access to the data, controlling permissions and security.

Basic Syntax:

GRANT : Provides specific privileges to a user or role.

GRANT SELECT, INSERT ON TableName TO UserName;

REVOKE : Removes specific privileges from a user or role.

DBMS NOTES 5
REVOKE DELETE ON TableName FROM UserName;

4. TCL (Transaction Control Language):

Purpose: Manages transactions within a database.

Basic Syntax:

COMMIT : Saves all changes made during the current transaction.

COMMIT;

ROLLBACK : Undoes changes made during the current transaction.

ROLLBACK;

SAVEPOINT : Sets a point within a transaction to which you can later roll
back.

SAVEPOINT SavepointName;

5. DQL (Data Query Language):

Purpose: Focuses on querying and retrieving data from the database.

Basic Syntax:

SELECT : Retrieves data from one or more tables.

SELECT Column1, Column2


FROM TableName
WHERE Condition;

Schemas, Subschemas, & Instances: Simplified Explanation


1. Schemas:

What is a Schema?

DBMS NOTES 6
A schema is like the blueprint or plan for a house. It defines the overall
structure and organization of a database.

Layman Example:

Imagine building a house. The architectural drawings that specify where the
rooms, doors, and windows will be represent the schema for the house.

2. Subschemas:

What is a Subschema?

A subschema is like a customized view of a room in the house. It focuses on


specific details for a particular person or group.

Layman Example:

In the house, everyone might have their own way of arranging the furniture in
the living room. Each arrangement is like a subschema tailored to an
individual's preference.

3. Instances:

What is an Instance?

An instance is like the actual furniture, people, and decorations in the rooms
of the house at a particular moment. It represents the current state.

Layman Example:

If the living room furniture is arranged for a cozy movie night, that
arrangement is an instance of the living room at that specific time.

4. Schema Evolution:

What is Schema Evolution?

Schema evolution is like renovating the house over time. It involves making
changes to the original plan to adapt to new needs or trends.

Layman Example:

If you decide to add a home office to the house because you started working
from home, that's a form of schema evolution.

5. Schema Integration:

What is Schema Integration?

DBMS NOTES 7
Schema integration is like combining different room designs from different
plans into a harmonious whole.

Layman Example:

If you merge ideas from different interior design plans to create a cohesive
look for the entire house, that's similar to schema integration.

In summary, think of a schema as the blueprint for a database (like a house plan),
subschemas as customized views for specific users (like arranging furniture in a
room), instances as the current state of the data (like the current furniture
arrangement), schema evolution as adapting the plan over time (like renovating the
house), and schema integration as merging different plans into a unified design (like
combining various interior design ideas).

3-Schema Architecture
The three-schema architecture is a conceptual framework that separates a database
system into three distinct components or schemas. This architecture was introduced
by the ANSI/X3/SPARC committee and is widely used for designing and managing
database systems. The three schemas are the User Schema, the Logical Schema,
and the Physical Schema.

1. User Schema:
Purpose:

Represents the way individual users perceive the data.

Defines the views and access privileges for different user groups.

Components:

User views, which are tailored for specific user requirements.

Access control to restrict or grant permissions for data manipulation.

Example:

In an online shopping database, the user schema might have views for
customers to see their order history, and another view for administrators to
manage product inventory.

2. Logical Schema:

DBMS NOTES 8
Purpose:

Represents the logical structure of the entire database.

Defines how data is organized and the relationships between different


entities.

Components:

Tables, relationships, constraints, and other logical structures.

Entity-relationship diagrams to illustrate the data model.

Example:

In the same online shopping database, the logical schema would define
tables for products, customers, orders, and their relationships, without
specifying how data is physically stored.

3. Physical Schema:
Purpose:

Represents how the data is physically stored and accessed on the hardware.

Describes the storage structures, indexing, and optimization techniques.

Components:

File organization, indexing methods, storage structures.

Query optimization strategies for efficient data retrieval.

Example:

Continuing with the online shopping database, the physical schema would
detail how product information is stored on disk, specifying details like file
organization and indexing methods.

Advantages of Three-Schema Architecture:


1. Data Independence:

Changes in one schema do not affect the other schemas. For example,
modifying the physical storage does not impact user views.

2. Security and Privacy:

User schema allows for controlled access, ensuring sensitive information is


only accessible to authorized users.

DBMS NOTES 9
3. Flexibility:

Users can have customized views without affecting the overall structure of
the database.

4. Maintenance:

Logical and physical schemas can be modified for performance or


organizational needs without disrupting user interfaces.

The three-schema architecture provides a clear separation of concerns, allowing for


efficient management, customization, and evolution of database systems. It
enhances data independence and provides a framework for adapting to changing
requirements.

1. Authorization and Authentication:


Authorization:

Definition: Authorization is the process of granting or denying access rights and


permissions to users or systems based on their identity and level of trust.

Purpose:

Determines what actions users are allowed to perform on a system or with


specific resources.

Ensures that only authorized individuals can access certain functionalities or


data.

Layman Example:

Think of a nightclub where the bouncer checks your ID before allowing you
inside. The process of checking your name on the guest list and confirming
your access is similar to authorization.

Authentication:

Definition: Authentication is the process of verifying the identity of an individual


or system, usually through credentials such as usernames and passwords.

Purpose:

Confirms the claimed identity of a user or system.

Ensures that only legitimate users gain access to the system.

DBMS NOTES 10
Layman Example:

When you log in to your email account by entering your username and
password, you are going through the authentication process to prove that
you are the authorized user.

2. Data Hiding and Data Abstraction:


Data Hiding:

Definition: Data hiding is a programming concept that restricts access to certain


details of an object and only exposes what is necessary for the outside world.

Purpose:

Protects the internal implementation details of an object.

Prevents unintended modifications to sensitive data.

Layman Example:

Consider a car. As a driver, you don't need to know the intricate details of the
engine; you interact with the dashboard and controls. The engine details are
hidden from you, promoting simplicity and safety.

Data Abstraction:

Definition: Data abstraction is the process of simplifying complex systems by


modeling classes based on their essential properties and behaviors, while hiding
unnecessary details.

Purpose:

Focuses on what an object does rather than how it achieves it.

Simplifies the interaction with complex systems by providing a high-level


view.

Layman Example:

When using a smartphone, you don't need to know the intricacies of how
each app works; you interact with abstract functionalities like messaging or
navigation, simplifying the user experience.

3. Data Independence:
Data Independence:

DBMS NOTES 11
Definition: Data independence is the ability to make changes in the database
structure without affecting the application programs or user views.

Types:

Logical Data Independence: Changes in the logical schema do not affect


the external schemas.

Physical Data Independence: Changes in the physical storage do not


affect the logical or external schemas.

Layman Example:

Think of a library system. If the librarian decides to reorganize the books on


the shelves without changing how borrowers request books, that's similar to
logical data independence. If they decide to switch from paper cards to a
computerized catalog without affecting how borrowers check out books,
that's like physical data independence.

Summary:
1. Authorization and Authentication:

Authorization: Decides what actions you can perform (nightclub entry


analogy).

Authentication: Confirms your identity (email login analogy).

2. Data Hiding and Data Abstraction:

Data Hiding: Protects internal details (car engine analogy).

Data Abstraction: Simplifies complex systems (smartphone app analogy).

3. Data Independence:

Allows changes in the database structure without affecting applications


(library reorganization and catalog switch analogies).

2-Tier Architecture:
Definition:

2-tier architecture, also known as client-server architecture, is a computing


model where the application's presentation layer and data management are
combined into a single software application or system.

DBMS NOTES 12
Components:

1. Client Tier:

The user interface or presentation layer that interacts directly with the user.

Responsible for processing user input and displaying results.

2. Database Tier:

Manages the data storage, retrieval, and processing.

Handles database operations such as queries, updates, and transactions.

Characteristics:

Direct Communication: The client communicates directly with the database


server.

Limited Scalability: Scaling is achieved by upgrading either the client or the


server, making it less scalable than 3-tier architecture.

Thinner Client: The client has less processing logic; more processing occurs on
the server.

Example:

A traditional desktop application where the user interface and database


operations are handled on the user's machine.

3-Tier Architecture:
Definition:

3-tier architecture is a computing model that divides an application into three


interconnected components or tiers: the presentation tier, the application tier
(business logic), and the data tier.

Components:

1. Presentation Tier (Client):

Manages the user interface and user interaction.

Sends user requests to the application server.

2. Application Tier (Server):

Contains the business logic and application processing.

DBMS NOTES 13
Interprets user requests, processes them, and communicates with the data
tier.

3. Data Tier (Database):

Manages data storage, retrieval, and processing.

Handles database operations and interacts with the application server.

Characteristics:

Scalability: Each tier can be scaled independently, providing better scalability


compared to 2-tier architecture.

Enhanced Security: The data tier is separate, adding a layer of security


between the client and the database.

Centralized Business Logic: Business logic is centralized in the application


server, reducing redundancy.

Example:

An e-commerce website where the user interacts with a web browser


(presentation tier), the website's server handles business logic (application tier),
and the database stores product and user information (data tier).

Key Differences:
1. Number of Tiers:

2-Tier: Consists of two tiers - client and database.

3-Tier: Consists of three tiers - presentation, application, and data.

2. Communication Flow:

2-Tier: Direct communication between the client and the database.

3-Tier: Communication flows from the client to the application server, and
then to the database.

3. Scalability:

2-Tier: Limited scalability; upgrading one tier affects the entire system.

3-Tier: Improved scalability; each tier can be scaled independently.

4. Security:

2-Tier: Security measures need to be implemented primarily on the client.

DBMS NOTES 14
3-Tier: Enhanced security with a separate data tier, reducing direct access
to the database.

5. Business Logic:

2-Tier: Business logic is often embedded in the client application.

3-Tier: Business logic is centralized in the application server, promoting


consistency and manageability.

Mapping:
Mapping Cardinality:

Definition : Mapping cardinality describes the relationship between entities in a


data model by specifying the number of instances in one entity that are
associated with the number of instances in another entity.

Mapping Ratio:

Definition: Mapping ratio refers to the numerical relationship between instances


in one entity compared to instances in another entity.

Types:
1. One-to-One (1:1):

Description:

Each instance in one entity is associated with exactly one instance in


another entity, and vice versa.

Example:

A mapping between a "Person" entity and a "Passport" entity where each


person has only one passport, and each passport belongs to only one
person.

2. One-to-Many (1:N):

Description:

Each instance in one entity is associated with zero or more instances in


another entity, but each instance in the second entity is associated with at
most one instance in the first entity.

Example:

DBMS NOTES 15
A mapping between a "Department" entity and an "Employee" entity where
each department has many employees, but each employee belongs to only
one department.

3. Many-to-One (N:1):

Description:

The reverse of one-to-many, where each instance in one entity is associated


with at most one instance in another entity, but each instance in the second
entity can be associated with multiple instances in the first entity.

Example:

A mapping between a "Student" entity and a "University" entity where each


student attends only one university, but each university may have many
students.

4. Many-to-Many (N:N):

Description:

Each instance in one entity can be associated with zero or more instances in
another entity, and vice versa.

Example:

A mapping between a "Book" entity and an "Author" entity where each book
can have multiple authors, and each author can write multiple books.

Data Models:
1. Hierarchical Data Model:

Structure:

Organized in a tree-like structure with a root representing the main entity,


and branches representing relationships.

Example:

An organization chart where each employee reports to a manager, creating a


hierarchy.

2. Network Data Model:

Structure:

DBMS NOTES 16
Similar to the hierarchical model but allows multiple relationships between
entities, forming a network.

Example:

A university database where a course may have multiple instructors and


multiple prerequisites.

3. Relational Data Model:

Structure:

Organized into tables (relations) with rows representing instances and


columns representing attributes.

Example:

A database for a library where there are tables for books, authors, and
borrowers, each related through unique identifiers.

4. Entity-Relationship (ER) Model:

Structure:

Represents entities, attributes, and relationships using diagrams.

Example:

A hospital management system where entities include patients, doctors, and


nurses, and relationships show who treats whom.

5. Object-Oriented Data Model:

Structure:

Organizes data into objects with attributes and methods, reflecting real-world
entities.

Example:

A multimedia database where images, videos, and audio files are treated as
objects with properties and behaviors.

DBMS NOTES 17

You might also like