Data base e
Data base e
user's view, the physical storage of data, and the overall logical structure. It is defined by the
ANSI/SPARC (American National Standards Institute/Standards Planning and
Requirements Committee) and includes the following three levels:
Focus: How the data is actually stored — e.g., indexes, file structures, and access
paths.
Example: Data stored in a binary file with indexing for fast retrieval.
Description: Describes what data is stored and the relationships among the data.
Example: A database model showing tables for Students, Courses, and Enrollments.
Description: The user's view of the database; can vary for different users.
Focus: How users interact with data; allows for multiple views depending on user
roles.
Example: A teacher sees student grades, while students only see their own
information.
Data Abstraction: Hides the complexity of the physical storage from users.
Data Independence:
o Logical Data Independence: Changes in the conceptual level don't affect the
external views.
Q2. General Architecture of a Database System
The General Architecture of a database system shows how different components interact to
manage and use the database efficiently. It includes several layers and modules that work
together to process data, manage storage, and ensure security and consistency.
1. Users
Types:
o End Users: Access data through applications (e.g., students checking results).
🔹 a. Query Processor
Includes:
🔹 b. Storage Manager
Includes:
o Buffer Manager
o File Manager
4. Database
pgsql
CopyEdit
[ Users ]
[ DBMS ]
The Relational Model is the most widely used data model in database systems. It was
introduced by E.F. Codd in 1970 and represents data in the form of tables (relations).
Example:
101 Alice 20
102 Bob 21
2. Tuple (Row)
3. Attribute (Column)
4. Domain
5. Schema
A schema is the structure of the database – the definition of tables and their
relationships.
1. Entity
Types:
2. Attributes
Types:
3. Relationship
o One-to-One (1:1)
o One-to-Many (1:N)
o Many-to-Many (M:N)
4. Keys
📊 ER Diagram Symbols
Concept Symbol
Entity Rectangle
Attribute Ellipse
Relationship Diamond
📌 Purpose of ER Model
✔ Definition:
✅ After 1NF:
✔ Definition:
Every non-prime attribute is fully functionally dependent on the entire primary key
(no partial dependency).
👉 Issue: StudentName depends only on StudentID, not the full key (StudentID + Course).
✅ After 2NF:
Student Table:
StudentID StudentName
101 Alice
StudentID StudentName
Enrollment Table:
101 Math 85
101 English 90
✔ Definition:
101 Alice D1 CS
✅ After 3NF:
Student Table:
101 Alice D1
Department Table:
DeptID DeptName
D1 CS
D2 Physics
🧠 Summary Table
The Projection Operator, denoted by π (pi), is used in relational algebra to select specific
columns (attributes) from a relation (table).
✅ Definition:
The projection operator returns a new relation containing only the specified attributes,
removing duplicates automatically.
📌 Syntax:
php-template
CopyEdit
π<attribute_list>(Relation_Name)
📊 Example:
101 Alice 20 CS
102 Bob 21 CS
103 Charlie 20 IT
scss
CopyEdit
πName(Student)
Result:
Name
Alice
Bob
Name
Charlie
scss
CopyEdit
πAge,Dept(Student)
Result:
Age Dept
20 CS
21 CS
20 IT
Note: If there were duplicate rows in the output, projection would eliminate them.
🎯 Key Points:
It’s useful when you only need specific attributes from a table.
In relational algebra, Selection and Projection are two fundamental operations used to
retrieve specific data from a relation (table).
✔ Definition:
The Selection operator (σ) is used to select rows (tuples) from a relation that satisfy a given
condition.
📌 Syntax:
php-template
CopyEdit
σ<condition>(Relation_Name)
📊 Example:
Given a relation Student:
101 Alice 20 CS
102 Bob 21 CS
103 Charlie 20 IT
bash
CopyEdit
σDept = 'CS'(Student)
Result:
101 Alice 20 CS
102 Bob 21 CS
✔ Definition:
The Projection operator (π) is used to select specific columns (attributes) from a relation.
📌 Syntax:
php-template
CopyEdit
π<attribute_list>(Relation_Name)
📊 Example:
scss
CopyEdit
πName(Student)
Result:
Name
Alice
Name
Bob
Charlie
scss
CopyEdit
πName(σDept = 'CS'(Student))
Step-by-step:
Final Output:
Name
Alice
Bob
🎯 Summary Table:
The Join Operator (⨝) is used in relational algebra to combine related tuples from two
different relations (tables) based on a common attribute.
✅ 1. Purpose of Join
Matches rows from two relations based on a specified condition (usually a common
key).
Symbol: R ⨝θ S
Combines tuples from R and S where the condition θ (e.g., =, <, >) is true.
Example:
nginx
CopyEdit
2. Equi Join
A special case of Theta Join where the condition is based on equality (=).
Automatically joins two relations by matching attributes with the same name and
removing duplicates in the result.
Syntax:
nginx
CopyEdit
R⨝S
Student:
101 Alice D1
102 Bob D2
Department:
DeptID DeptName
D1 CS
D2 IT
Natural Join:
nginx
CopyEdit
Student ⨝ Department
Result:
101 Alice D1 CS
102 Bob D2 IT
Not a part of pure relational algebra, but common in SQL and extended relational models:
Left Outer Join: Keeps all rows from the left table.
Right Outer Join: Keeps all rows from the right table.
In SQL (Structured Query Language), commands are grouped based on their purpose. Two of
the main categories are DDL and DML.
Purpose:
Used to define and modify the structure** of database objects like tables, schemas, indexes,
etc.
CREATE Creates a new table, view, or database CREATE TABLE Students (...);
ALTER Modifies the structure of an existing table ALTER TABLE Students ADD Age INT;
Purpose:
Used to manipulate data stored in tables (insert, update, delete, retrieve).
INSERT Adds new data into a table INSERT INTO Students VALUES (101, 'Alice');
DELETE Removes data from a table DELETE FROM Students WHERE ID = 101;
The NOT operator in SQL is a logical operator used to negate a condition. It returns the
opposite result of the condition it's applied to.
✅ Syntax:
sql
CopyEdit
🔄 How It Works:
📌 Examples:
sql
CopyEdit
sql
CopyEdit
sql
CopyEdit
sql
CopyEdit
SELECT * FROM Courses
);
🧠 Quick Notes:
NOT is often used with operators like IN, BETWEEN, EXISTS, LIKE.
Schema Design: Define and design tables, indexes, relationships, constraints, and
views.
User Access Management: Create and manage user accounts, roles, and privileges.
Backup and Recovery: Design and implement data backup strategies (full,
incremental, etc.) and ensure disaster recovery procedures are in place.
Audit Trails: Monitor and maintain logs for tracking user activities to ensure data
integrity and compliance.
Indexing: Create and manage indexes to improve query speed and performance.
Backup Strategy: Plan, execute, and monitor regular backups to protect data from
loss.
7. Database Maintenance
Data Migration: Manage data migration and transformation during system upgrades
or migrations to new platforms.
Clustering: Implement and manage database clustering solutions for high availability.
Disaster Recovery Plans: Design and test disaster recovery strategies, including
setting up redundant systems for critical applications.
Experience with backup and recovery solutions, disaster recovery planning, and
security practices.
SQL Features
SQL (Structured Query Language) is a powerful language used for managing and
manipulating relational databases. It provides various features that help in data
management, querying, and security.
1. Data Querying
Select Data: SQL allows users to query the database to retrieve data using the SELECT
statement.
Example:
sql
CopyEdit
Filtering Data: SQL enables filtering of data based on specific conditions using the
WHERE clause.
Example:
sql
CopyEdit
2. Data Manipulation
Insert Data: SQL allows insertion of new data into tables using the INSERT INTO
statement.
Example:
sql
CopyEdit
INSERT INTO Students (Name, Age, Department) VALUES ('Alice', 21, 'CS');
Update Data: SQL allows modification of existing data with the UPDATE statement.
Example:
sql
CopyEdit
Delete Data: SQL allows deletion of data from tables using the DELETE statement.
Example:
sql
CopyEdit
3. Data Definition
Create Tables: SQL allows creation of new tables, views, or schemas using the
CREATE statement.
Example:
sql
CopyEdit
Example:
sql
CopyEdit
Drop Tables: SQL allows deletion of tables from the database with the DROP
statement.
Example:
sql
CopyEdit
4. Data Integrity
Primary Key: SQL allows enforcing a primary key to uniquely identify each record in a
table.
Example:
sql
CopyEdit
Foreign Key: SQL supports foreign keys to maintain referential integrity between two
related tables.
Example:
sql
CopyEdit
CREATE TABLE Enrollments (StudentID INT, CourseID INT, FOREIGN KEY (StudentID)
REFERENCES Students(ID));
Constraints: SQL allows defining constraints like NOT NULL, UNIQUE, CHECK, etc., to
maintain data validity.
Example:
sql
CopyEdit
CREATE TABLE Students (ID INT NOT NULL, Age INT CHECK (Age >= 18));
5. Data Control
Granting Permissions: SQL allows specifying user privileges and permissions using
the GRANT statement.
Example:
sql
CopyEdit
Revoking Permissions: SQL also enables revoking user privileges using the REVOKE
statement.
Example:
sql
CopyEdit
Aggregate Functions: SQL supports built-in aggregate functions like COUNT(), SUM(),
AVG(), MAX(), MIN() to calculate summaries of data.
Example:
sql
CopyEdit
Grouping Data: SQL enables grouping data using the GROUP BY clause.
Example:
sql
CopyEdit
Filtering Groups: You can filter groups with the HAVING clause, which is like WHERE
but for groups.
Example:
sql
CopyEdit
SELECT Department, COUNT(*) FROM Students GROUP BY Department HAVING COUNT(*) >
10;
9. Transactions
Example:
sql
CopyEdit
BEGIN;
COMMIT;
sql
CopyEdit
ROLLBACK;
Views: SQL allows the creation of views to represent complex queries as virtual
tables.
Example:
sql
CopyEdit
Indexes: SQL supports the creation of indexes to speed up the retrieval of rows from
large tables.
Example:
sql
CopyEdit
1. Storing Metadata
Definition: The primary function of the data dictionary is to store metadata about
the database objects, such as:
Example: Information on the structure of a table (columns, data types) is stored in the data
dictionary.
Definition: The data dictionary helps maintain data integrity by storing information
about constraints such as:
o Primary keys
o Foreign keys
o Unique constraints
o Check constraints
This ensures that the relationships and integrity of data are always maintained when
interacting with the
3. Access Control
Definition: The data dictionary stores information about user roles and permissions,
managing who can access which data and what actions they are allowed to perform
(e.g., SELECT, INSERT, UPDATE, DELETE).
Example: The system stores details of users, their access privileges, and granted roles in the
data dictionary.
4. Schema Management
Definition: The data dictionary keeps track of the database schema, which is the
organization of tables and the relationships between them. It can also store the
schema of indexes, views, and other objects, allowing administrators to easily
manage the database structure.
Definition: It stores data types for columns in tables, which helps ensure consistency
when data is inserted or queried. The data dictionary keeps track of:
7. Query Optimization
8. System Monitoring
Definition: The data dictionary also stores information about the system’s
performance, including statistics like table sizes, row counts, and index usage. This
helps database administrators monitor and optimize the database performance.
9. Database Documentation
Table Name Column Name Data Type Key Default Value Constraints
The data dictionary provides critical information about database schema and
metadata.
It helps ensure data integrity, data access control, and system performance
optimization.
The dictionary plays a significant role in query optimization by providing insight into
database structure and relationships.
In an un-normalized database, data is typically stored in a form that has not undergone the
process of normalization. This can lead to various types of data anomalies and
redundancies. In such a database, multiple dependencies can exist that can cause issues like
update anomalies, insertion anomalies, and deletion anomalies. To understand these
dependencies, let's break down some common types:
Example: Suppose we have a table where a student can have multiple phone
numbers and email addresses, stored together:
Here, the student's phone numbers and email addresses are stored together, and the
dependency between Phone Numbers and Email Addresses is a multivalued dependency.
This is problematic as adding or removing a phone number or email results in repeating the
student's name and ID
✅ 2. Partial Dependency
Example: Consider a table where a StudentCourse table has a composite primary key
(StudentID, CourseID) and stores the course's instructor and the student's grade:
Here, the Instructor depends only on CourseID, which is a part of the composite key, but not
on the full primary key (StudentID, CourseID). This is a partial dependency because
Instructor is not fully dependent on the entire key. This violates the rule of 2NF (Second
Normal Form).
✅ 3. Transitive Dependency
Here, Instructor depends on CourseID, and Grade depends on both StudentID and CourseID.
The dependency Instructor → CourseID → Grade forms a transitive dependency. This could
be avoided by splitting the data into separate tables to remove redundancy.
✅ 4. Functional Dependency
Definition: A functional dependency occurs when one attribute (or set of attributes)
uniquely determines another attribute in the table.
Example: A table may contain information like StudentID, CourseID, Instructor, and
Grade, where StudentID → Grade (a student’s grade is determined by their
StudentID), and CourseID → Instructor (the course determines the instructor).
✅ 5. Join Dependency
Example: If a student’s information (student ID, course ID, instructor, and grade) is
stored in a single table, a join dependency exists when we attempt to split the data
into logical smaller tables (e.g., Student, Course, and Enrollment) but cannot
maintain all relationships effectively without recombining them
Example:
Functional
One attribute determines another attribute StudentID → Grade
Dependency
🚀 Conclusion: