Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

Sanjivani Rural Education Society’s

Sanjivani College of Engineering, Kopargaon-423603


(An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited,

Department of Information Technology


(NBA Accredited)

Database Management System

Group No :18

Guided BY :-Prof.B.B.Pawar
Group Members

Name Roll No

Sanjana Lahamage 76
Vinod Nangare 86
Harshal Patil 96
Rutuja Rajput 106
Parvej Shaikh 116
Bharti Sonawane 126
Vaishnavi Zarekar 136
ER-Model
1. Draw ER model with any suitable database and implement in MySQL DDL & DML
commands.

ER Diagram For Online Voting System

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information
ER-Model
DDL Queries :

1. Creating Table For Candidate :


CREATE TABLE Candidates (
CandidateID INT PRIMARY KEY,
Name VARCHAR(100),
Party VARCHAR(100),
Position VARCHAR(100)
);
2. Creating Table For Voter :
CREATE TABLE Votes (
VoteID INT PRIMARY KEY,
VoterID INT,
CandidateID INT,
FOREIGN KEY (VoterID) REFERENCES Voters(VoterID),
FOREIGN KEY (CandidateID) REFERENCES Candidates(CandidateID)
);

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information
ER-Model
3.Creating Table For Voters :
CREATE TABLE Voters (
VoterID INT PRIMARY KEY,
Name VARCHAR(100),
Age INT,
Address VARCHAR(255)
);

DML Queries :
1. Inserting data into the Candidates table:

INSERT INTO Candidates (C_ID, Name, Party)


VALUES (1, 'John Doe', 'Independent', 'President');

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information
ER-Model

2.Inserting data into the Votes table (assuming a vote is cast by a voter for
a candidate):
INSERT INTO Votes (VID, Voter_ID, C_ID)
VALUES (1, 1, 1);

3.Inserting data into the Voters table:


INSERT INTO Voters (VoterID, Name, Age, NIC)
VALUES (1, 'Alice Smith', 30, '123 Main Street’);

These commands provide a basic structure for managing candidates, votes, and voters in an online voting system.

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information
Nested Subquery
2. Demonstrate the nested subquery with any suitable database in
MySQL.
Employee id name Department id
department_id name
1 Alice 1
1 Engineering
2 Bob 2
3 Charlie 1 2 Marketing
4 David 3 3 HR
5 Eve 1

Employee Table Department Table

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology
Nested Subquery

SELECT name

FROM employees

WHERE department_id = (

SELECT department_id

FROM departments

WHERE name = 'Engineering'

);

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology
Output
If we run the provided query, the output would be:

These are the names of employees who belong to the "Engineering"


department, as per the nested subquery condition.

Digital Electronics & Computer Organization– CIA PART B Presentation I Guided by Mr. A. A. Barbind Department of Information
Triggers
3. Implement and demonstrate use of triggers with any suitable database in
MySQL
Use of Trigger :

"Triggers are essential components in programming that automatically initiate actions based on certain
conditions or events. They serve as powerful tools to execute specific tasks, such as updating a database,
sending notifications, or performing calculations, when predefined conditions are met. Integrating triggers
into your application architecture enhances efficiency, automation, and responsiveness, thereby streamlining
processes and improving user experiences."

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology
Triggers
First, let's create the tables:

CREATE TABLE orders (


order_id INT AUTO_INCREMENT PRIMARY KEY,
customer_name VARCHAR(100),
total_amount DECIMAL(10, 2)
);
CREATE TABLE order_logs (
log_id INT AUTO_INCREMENT PRIMARY KEY,
action VARCHAR(50),
order_id INT,
log_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (order_id) REFERENCES orders(order_id)
);

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology
Triggers
Now, let's create a trigger that logs every time a new order is inserted into the orders table:

DELIMITER //
CREATE TRIGGER after_order_insert
AFTER INSERT ON orders
FOR EACH ROW
BEGIN
INSERT INTO order_logs (action, order_id)
VALUES ('Inserted', NEW.order_id);
END;
//
DELIMITER ;

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology
Triggers
Now, let's insert a new order into the orders table and observe how the trigger logs the action in the order_logs table:

INSERT INTO orders (customer_name, total_amount) VALUES ('John Doe', 100.00);

After executing this insert statement, if we query the order_logs table, we should see a new entry indicating that an
order was inserted:

SELECT * FROM order_logs;

Output Will Look this :

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology
Join Dependencies and the Normal Form
4. Join Dependencies and the Fifth Normal Form

Join dependencies are a concept in database normalization theory, particularly relevant to higher normal forms
beyond 3NF (Third Normal Form). The Fifth Normal Form (5NF) deals with eliminating join dependencies.

1.Join Dependency:
• A join dependency exists when a table can be reconstructed by joining two or more other tables. In simpler
terms, it's a constraint on a relation (table) where its tuples can be recreated by joining other tables together.
• For example, let's say we have three tables: A, B, and C. If we can reconstruct table A by joining B and C
together (without any additional attributes), then there exists a join dependency.

2.Fifth Normal Form (5NF):


• Fifth Normal Form (5NF) aims to eliminate join dependencies from a relational schema.
• A relation is in 5NF if and only if it is in 4NF and it cannot be split into two or more simpler relations without
loss of information.
• 5NF ensures that each join dependency is eliminated, thereby minimizing redundancy and ensuring that the
database schema is free from certain types of anomalies.

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology
Join Dependencies and the Normal Form
Example:
Let's consider a database schema with three tables:
• Students (student_id, student_name)
• Courses (course_id, course_name)
• Enrollments (student_id, course_id, semester)
• Here, Enrollments table represents a many-to-many relationship between Students and Courses.
• If we can reconstruct the Enrollments table by joining Students and Courses (using student_id and course_id),
then there exists a join dependency.
• To achieve 5NF, we might decompose Enrollments into two separate tables: Student_Courses (student_id,
course_id) and Semester_Details (student_id, course_id, semester), where Student_Courses represents the
relationship between students and courses, and Semester_Details provides additional details such as semester
information.

In summary, join dependencies are constraints that indicate a relation can be reconstructed by joining other relations
together. Fifth Normal Form (5NF) aims to eliminate these dependencies to ensure a more robust and efficient database
schema, free from certain types of anomalies.

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology
Log-Based Recovery
5.Log-Based Recovery

Log-based recovery is a technique used in database management systems (DBMS) to ensure data consistency and recover from
failures. It involves the use of transaction logs, which record all changes made to the database, to restore the database to a
consistent state in the event of a failure or system crash.

Here's how log-based recovery typically works:


1. Transaction Logs: Every DBMS maintains a transaction log, which is a sequential record of all modifications
made to the database. Each log entry contains information about the operation (such as INSERT, UPDATE,
DELETE), the affected data (such as table name and values), and a timestamp.
2. Logging Changes: Whenever a transaction modifies data in the database, the DBMS logs the changes to the
transaction log before actually applying them to the database itself. This ensures that a record of the changes is
always available, even if the system crashes before the changes are permanently stored.
3. Commit and Rollback: When a transaction commits, indicating that all its changes should be made permanent,
the corresponding log entries are marked as committed. Conversely, if a transaction rolls back, its log entries can
be discarded.
4. Recovery Process: In the event of a system failure or crash, the DBMS uses the transaction log to restore the
database to a consistent state. It replays the logged transactions from the most recent checkpoint (a point in
time where all changes up to that point are known to be safely stored) to reconstruct the database.

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology
Log-Based Recovery

5. Redo and Undo Operations: The recovery process typically involves two types of operations:
• Redo: Reapplying committed transactions from the log to ensure that all changes are correctly
reapplied to the database.
• Undo: Rolling back uncommitted or partially committed transactions by undoing their effects on
the database.

6. Checkpointing: Periodically, the DBMS creates checkpoints to reduce the amount of work
required during recovery. A checkpoint is a point in time where all modifications up to that point
have been written to disk. It involves flushing all modified data from memory to disk and
updating the checkpoint record in the log.

Overall, log-based recovery ensures data consistency and durability by recording all changes to the database
in a transaction log and using that log to recover the database to a consistent state in the event of failures or
crashes. It is a fundamental mechanism employed by DBMS to maintain data integrity and reliability.

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology
MongoDB
6. Implement any suitable database application in MongoDB and perform
Indexes.
1. Create a Database and Collection:
use bookstore
db.createCollection("books")

2. Insert Sample Data:

db.books.insertMany([
{ title: "The Great Gatsby", author: "F. Scott Fitzgerald", category: "Fiction" },
{ title: "To Kill a Mockingbird", author: "Harper Lee", category: "Fiction" },
{ title: "The Catcher in the Rye", author: "J.D. Salinger", category: "Fiction" },
{ title: "1984", author: "George Orwell", category: "Science Fiction" },
{ title: "Pride and Prejudice", author: "Jane Austen", category: "Classic" }
])

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology
MongoDB
3.Create Indexes:
Let's create an index on the title field to improve the performance of queries that filter by the book title.
db.books.createIndex({ title: 1 })

4.Perform Queries:
Now, you can perform queries on the books collection. For example, to find all books in the "Fiction" category:
db.books.find({ category: "Fiction" })

5.Query Optimization with Indexes:


MongoDB uses indexes to quickly locate data without scanning every document in a collection. By creating indexes on
fields that are frequently used in queries, you can significantly improve query performance.

In this example, we created a simple database application in MongoDB to manage a collection of books and
performed indexing on the title field to optimize query performance. Remember to consider your application's
specific requirements when creating indexes to ensure they provide the most benefit.

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology
Conclusion
"In conclusion, we covered essential topics in database management, including ER modeling and
implementation in MySQL, nested subqueries for complex data retrieval, normalization concepts like
Join Dependencies and Fifth Normal Form (5NF), log-based recovery techniques, and MongoDB
application development with indexing for query optimization. Understanding these concepts is crucial
for designing efficient, reliable, and scalable database systems that meet the needs of modern
applications."

Database Management System CIA PART B Presentation I Guided by Prof:B.B.Pawar Department of Information Technology

You might also like