Dbms Notes (1)
Dbms Notes (1)
The primary goal of a DBMS is to provide an environment that is both convenient and
efficient for people to storing and retrieving information.
Physical level
Logical level
View level
[Link] is a schema?
Let R be a relation variable and let X and Y be arbitrary subsets of the set of attributes of
R. then we say that Y is functionally dependent on-in symbols,
X->Y
(read ―X functionally determines Y,‖ or simply ― X arrow Y ‖)- if and only if in every
possible legal value of R, each X Value has associated with it precisely one Y value.
PART-B
Explain the system structure of a database system with neat block diagram
A Database Management System (DBMS) is software that allows users to define, store,
maintain, and manage data in a structured and efficient manner. It acts as an intermediary
between data and users, allowing disparate data from different applications to be
managed. A DBMS simplifies the complexity of data processing by providing tools to
organize data, ensure its integrity, and prevent unauthorized access or loss of data.
In today's data-driven world, DBMS are essential for applications such as banking
systems, e-commerce platforms, education, and medical systems. They not only store and
manage large amounts of data, but also provide functionality that provides performance,
security, and scalability for multiple users with multiple access levels.
1. Query Processor
It interprets the requests (queries) received from end user via an application program into
instructions. It also executes the user request which is received from the DML compiler.
Query Processor contains the following components -
DML Compiler: It processes the DML statements into low level instruction (machine
language), so that they can be executed.
DDL Interpreter: It processes the DDL statements into a set of table containing meta
data (data about data).
Embedded DML Pre-compiler: It processes DML statements embedded in an
application program into procedural calls.
Query Optimizer: The Query Optimizer executes instructions generated by the DML
Compiler and improves query execution efficiency by choosing the best query plan,
considering factors such as indexing, join order, and available system resources. For
instance, if a query involves joining two large tables, the optimizer will select the best
join order to minimize query execution time.
2. Storage Manager
Storage Manager is an interface between the data stored in the database and the queries
received. It is also known as Database Control System. It maintains the consistency and
integrity of the database by applying the constraints and executing the DCL statements. It
is responsible for updating, storing, deleting, and retrieving data in the database. It
contains the following components:
Authorization Manager: It ensures role-based access control, i.e,. checks whether
the particular person is privileged to perform the requested operation or not.
File Manager: It manages the file space and the data structure used to represent
information in the database.
Buffer Manager: It is responsible for cache memory and the transfer of data
between the secondary storage and main memory.
3. Disk Storage
It contains the following essential components:
Data Files: It stores the actual data in the database.
Data Dictionary: It contains the information about the structure of database
objects such as tables, constraints, and relationships. It is the repository of
information that governs the metadata.
Indices: Provides faster data retrieval by allowing the DBMS to find records
quickly, improving query performance.
Levels of DBMS Architecture
The structure of a Database Management System (DBMS) can be divided into three main
components: the Internal Level, the Conceptual Level, and the External Level.
1. Internal Level
This level represents the physical storage of data in the database. It is responsible for
storing and retrieving data from the storage devices, such as hard drives or solid-state
drives. It deals with low-level implementation details such as data compression,
indexing, and storage allocation.
2. Conceptual Level
This level represents the logical view of the database. It deals with the overall
organization of data in the database and the relationships between them. It defines the
data schema, which includes tables, attributes, and their relationships. The conceptual
level is independent of any specific DBMS and can be implemented using different
DBMSs.
3. External Level
This level represents the user's view of the database. It deals with how users access the
data in the database. It allows users to view data in a way that makes sense to them,
without worrying about the underlying implementation details. The external level
provides a set of views or interfaces to the database, which are tailored to meet the needs
of specific user groups.
The three levels are connected via schema mapping, ensuring that changes at one level
(e.g., the conceptual level) are accurately reflected in the others. This process
maintains data independence, allowing changes in physical storage (internal level)
without affecting the logical or user views.
Role of Database Administrator (DBA)
In addition to these three levels, a DBMS also includes a Database
Administrator (DBA) component, which is responsible for managing the database
system. The DBA performs critical tasks such as:
Database design and architecture.
Security management: Implementing role-based access control (RBAC), encryption,
and ensuring strong authentication measures such as multi-factor authentication
(MFA).
Backup and recovery: Regularly creating backups and preparing recovery plans in
case of data loss.
Performance tuning: Optimizing database performance, including query
optimization, indexing, and resource management to ensure the DBMS runs
efficiently.
SQL commands are fundamental building blocks used to perform given operations
on database. The operations include queries of data. creating a table, adding data
to tables, dropping the table, modifying the table and set permission for users.
SQL Commands are mainly categorized into five categories:
RENAME TABLE
Rename an object existing in
RENAME old_table_name TO
the database
new_table_name;
Example:
Example:
Example:
Example:
Virtual: Views do not store physical data; only their definition (the SELECT query) is
stored in the database.
Dynamic: The data in a view is always up-to-date because it is computed at the time of
the query from the current data in the base tables.
Security: Views can restrict access to sensitive information by allowing users to see only
specific rows and columns of a table, rather than the entire base table.
Simplicity: Views can hide the complexity of data by joining multiple tables or using
aggregate functions, making interactions simpler for the user.
[Link] and explain the ER Diagram for banking Systems. (Home loan applications)
ER diagram is known as Entity-Relationship diagram. It is used to analyze to structure of
the Database. It shows relationships between entities and their attributes. An ER model
provides a means of communication.
This bank ER diagram illustrates key information about bank, including entities such as
branches, customers, accounts, and loans. It allows us to understand the relationships
between entities.
Bank Entity : Attributes of Bank Entity are Bank Name, Code and Address.
Code is Primary Key for Bank Entity.
Customer Entity : Attributes of Customer Entity are Customer_id, Name, Phone
Number and Address.
Customer_id is Primary Key for Customer Entity.
Branch Entity : Attributes of Branch Entity are Branch_id, Name and Address.
Branch_id is Primary Key for Branch Entity.
Account Entity : Attributes of Account Entity are Account_number, Account_Type
and Balance.
Account_number is Primary Key for Account Entity.
Loan Entity : Attributes of Loan Entity are Loan_id, Loan_Type and Amount.
Loan_id is Primary Key for Loan Entity.
Relationships are :
In this section, we will briefly discuss the different normalization levels and then explore
them deeper in the next section.
This normalization level ensures that each column in your data contains only atomic
values. Atomic values in this context means that each entry in a column is indivisible. It
is like saying that each cell in a spreadsheet should hold just one piece of information.
1NF ensures atomicity of data, with each column cell containing only a single value and
each column having unique names.
Eliminates partial dependencies by ensuring that non-key attributes depend only on the
primary key. What this means, in essence, is that there should be a direct relationship
between each column and the primary key, and not between other columns.
Third Normal Form (3NF)
Removes transitive dependencies by ensuring that non-key attributes depend only on the
primary key. This level of normalization builds on 2NF.
This is a more strict version of 3NF that addresses additional anomalies. At this
normalization level, every determinant is a candidate key.
5NF is the highest normalization level that addresses join dependencies. It is used in
specific scenarios to further minimize redundancy by breaking a table into smaller tables.
We have already highlighted all the data normalization levels. Let’s further explore each
of them in more depth with examples and explanations.
1NF ensures that each column cell contains only atomic values. Imagine a library
database with a table storing book information (title, author, genre, and borrowed_by). If
the table is not normalized, borrowed_by could contain a list of borrower names
separated by commas. This violates 1NF, as a single cell holds multiple values. The table
below is a good representation of a table that violates 1NF, as described earlier.
J. R. R. Fantas
The Lord of the Rings Emily Garcia, David Lee
Tolkien y
Harry Potter and the Sorcerer’s Fantas
J.K. Rowling Michael Chen
Stone y
The solution?
In 1NF, we create a separate table for borrowers and link them to the book table. These
tables can either be linked using the foreign key in the borrower table or a separate
linking table. The foreign key in the borrowers table approach involves adding a foreign
key column to the borrowers table that references the primary key of the books table.
This will enforce a relationship between the tables, ensuring data consistency.
Books table
Borrowers table
1 John Doe 1
2 Jane Doe 1
3 James Brown 1
4 Emily Garcia 2
5 David Lee 2
6 Michael Chen 3
This level of normalization, as already described, builds upon 1NF by ensuring there are
no partial dependencies on the primary key. In simpler terms, all non-key attributes must
depend on the entire primary key and not just part of it.
From the 1NF that was implemented, we already have two separate tables (you can check
the 1NF section).
Now, let’s say we want to link these tables to record borrowings. The initial approach
might be to simply add a borrower_id column to the books table, as shown below:
book_id borrower_id
title author genre
(PK) (FK)
J. R. R.
2 The Lord of the Rings Fantasy NULL
Tolkien
This might look like a solution, but it violates 2NF simply because the borrower_id only
partially depends on the book_id. A book can have multiple borrowers, but a single
borrower_id can only be linked to one book in this structure. This creates a partial
dependency.
The solution?
Book_borrowings table
borrowing_id (PK) book_id (FK) borrower_id (FK) borrowed_date
1 1 1 2024-05-04
2 2 4 2024-05-04
3 3 6 2024-05-04
This table establishes a clear relationship between books and borrowers. The book_id and
borrower_id act as foreign keys, referencing the primary keys in their respective tables.
This approach ensures that borrower_id depends on the entire primary key (book_id) of
the books table, complying with 2NF.
From the 2NF we already implemented, there are three tables in our library database:
Books table
Borrowers table
borrower_id (PK) name book_id (FK)
1 John Doe 1
2 Jane Doe 1
3 James Brown 1
4 Emily Garcia 2
5 David Lee 2
6 Michael Chen 3
Book_borrowings table
1 1 1 2024-05-04
2 2 4 2024-05-04
3 3 6 2024-05-04
The 2NF structure looks efficient, but there might be a hidden dependency. Imagine we
add a due_date column to the books table. This might seem logical at first sight, but it’s
going to create a transitive dependency where:
The due_date column depends on the borrowing_id (a non-key attribute) from the
book_borrowings table.
The borrowing_id in turn depends on book_id (the primary key) of the books table.
The implication of this is that due_date relies on an intermediate non-key attribute
(borrowing_id) instead of directly depending on the primary key (book_id). This violates
3NF.
The solution?
We can move the due_date column to the most appropriate table by updating the
book_borrowings table to include the due_date and returned_date columns.
1 1 1 2024-05-04 2024-05-20
2 2 4 2024-05-04 2024-05-18
3 3 6 2024-05-04 2024-05-10
What this means is that due_date now directly depends on the combined relationship
between book_id and borrower_id. In this context, book_id and borrower_id are acting as
a composite foreign key, which together form the primary key of the book_borrowings
table.
BCNF is a stricter version of 3NF. It ensures that every determinant (a set of attributes
that uniquely identify a row) in a table is a candidate key (a minimal set of attributes that
uniquely identify a row). The whole essence of this is that all determinants should be able
to serve as primary keys.
It ensures that every functional dependency (FD) has a superkey as its determinant. In
other words, if X —> Y (X determines Y) holds, X must be a candidate key (superkey) of
the relation. Please note that X and Y are columns in a data table.
As a build-up from the 3NF, we have three tables:
Books table
Borrowers table
1 John Doe 1
2 Jane Doe 1
3 James Brown 1
4 Emily Garcia 2
5 David Lee 2
6 Michael Chen 3
Book_borrowings table
1 1 1 2024-05-04 2024-05-20
2 2 4 2024-05-04 2024-05-18
3 3 6 2024-05-04 2024-05-10
While the 3NF structure is good, there might be a hidden determinant in the
book_borrowings table. Assuming one borrower cannot borrow the same book twice
simultaneously, the combination of book_id and borrower_id together uniquely identifies
a borrowing record.
This structure violates BCNF since the combined set (book_id and borrower_id) is not
the primary key of the table (which is just borrowing_id).
The solution?
To achieve BCNF, we can either decompose the book_borrowings table into two separate
tables or make the combined attribute set the primary key.
4NF deals with multi-valued dependencies. A multi-valued dependency exists when one
attribute can have multiple dependent attributes, and these dependent attributes are
independent of the primary key. It’s quite complex, but we will be exploring it deeper
using an example.
The library example we’ve been using throughout these explanations is not applicable at
this normalization level. 4NF typically applies to situations where a single attribute might
have multiple dependent attributes that don’t directly relate to the primary key.
Let’s use another scenario. Imagine a database that stores information about publications.
We will be considering a “Publications” table with columns, title, author,
publication_year, and keywords.
publication_id
title author publication_year keywords
(PK)
The keywords column has a multi-valued dependency on the primary key publication_id.
What this means is that a publication can have multiple keywords, and these keywords
are independent of the publication’s unique identifier.
The solution?
Publication_keywords table
1 Coming-of-Age
1 Legal
2 Fantasy
2 Epic
2 Adventure
3 Romance
3 Social Commentary
With this, we have successfully eliminated the multi-valued dependency and achieved
4NF.
5NF is the most complex form of normalization that eliminates join dependencies. This is
a situation where data needs to be joined from multiple tables to answer a specific query,
even when those tables are already in 4NF.
In simpler terms, 5NF ensures that no additional information can be derived by joining
the tables together that wasn’t already available in the separate tables.
Join dependencies are less likely to occur when tables are already normalized (in 3NF or
4NF), hence the difficulty in creating a clear and straightforward example for 5NF.
However, let’s take a look at this scenario where 5NF might be relevant:
Imagine a university database with normalized tables for “Courses” and “Enrollments.”
Courses table
Enrollments table
1 12345 101 A
2 12345 202 B
3 56789 301 A-
4 56789 401 B+
Assuming these tables are already in 3NF or 4NF, a join dependency might exist
depending on how data is stored. For instance, a course has a prerequisite requirement
stored within the “Courses” table as the “prerequisite_course_id” column.
This might seem efficient at first glance. However, consider a query that needs to retrieve
a student’s enrolled courses and their respective prerequisites. In this scenario, you would
need to join the “Courses” and “Enrollments” tables, then potentially join the “Courses”
table to retrieve prerequisite information.
The Solution?
To potentially eliminate the join dependency and achieve 5NF, we could introduce a
separate “Course Prerequisites” table:
Course_prerequisite table
202 101
301 NULL
401 202
This approach separates prerequisite information and allows efficient retrieval of enrolled
courses and their prerequisites in a single join between the “Enrollments” and
“Course_prerequisites” tables.
Note: We are assuming a student can only have one prerequisite per course.
5NF is a very complex and rare type of normalization, so as someone just starting their
learning journey in data, you might not find an application. However, it’s going to be
added knowledge and will make you prepared when you stumble on complex databases.
Develop an Entity Relationship model for a library management system. Clearly State the
problem Definition, Description, Business Rule and any assumption you make
Problem Definition
The objective is to design a database system for managing the core functions of a library.
The system needs to efficiently track the library's collection of books, manage member
information, record lending transactions, and handle reservation requests. This ER model
will serve as the blueprint for the database schema, ensuring data integrity and supporting
key business processes.
Description
The library management system must manage various entities and their relationships:
Books and Authors: A library holds many books. A single book can be written by
multiple authors, and an author can write multiple books. Books have key attributes like
ISBN, title, publication date, and genre.
Library Members: Individuals who can borrow books are registered as members. Each
member has a unique ID, name, contact details (phone, email), and registration date.
Lending and Returns: Members borrow specific book copies. The system must record
who borrowed which book copy, the date borrowed, and the expected return date. It also
needs to record the actual return date and track any fines incurred.
Inventory: The library may have multiple physical copies of the same book title. Each
copy has a unique identifier (e.g., accession number) and its current status (e.g.,
'available', 'on loan', 'reserved').
Reservations: Members can reserve book titles that are currently unavailable.
Business Rules
The following rules govern the system's operations and data integrity:
1. Unique Identifiers: Every entity instance must have a unique identifier (e.g., ISBN for a
book title, Member ID for a member, Copy ID for a book copy, Author ID for an author).
2. Borrowing Limit: A member may borrow a maximum of 5 book copies at any given
time.
3. Loan Duration: The standard loan period for any book copy is 14 days.
4. Fines: Fines are calculated for overdue books at a rate of $0.50 per day overdue.
5. Reservations: A member can only reserve a book title if all copies of that title are
currently loaned out.
6. Data Integrity: All book copies must be associated with an existing book title and a
library branch (if a multi-branch system is assumed).
Assumptions
The system operates within a single library branch (to simplify branch management; can
be extended later).
A 'Book Title' entity is distinct from a 'Book Copy' entity to manage inventory
effectively.
A book must have at least one author, and an author must have authored at least one book
in the system.
A simple reservation system is assumed, where the first person in the queue gets the next
available copy.
This model illustrates the entities (tables), their attributes (columns), and the relationships
between them.
Inventory Of BOOK_TITLE, One-to- One Book Title can have many Book
BOOK_COPY Many Copies.
(1:N)
Associative Entities: