Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views4 pages

Chapter 18 Databases (Extended Conc

Chapter 18 covers advanced concepts in database design, including the Relational Model and Entity-Relationship Model, emphasizing normalization and optimization techniques. It discusses transaction management, ACID properties, concurrency control, and advanced SQL techniques such as subqueries, triggers, and stored procedures. Additionally, it outlines backup and recovery methods, highlighting different recovery models and their applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Chapter 18 Databases (Extended Conc

Chapter 18 covers advanced concepts in database design, including the Relational Model and Entity-Relationship Model, emphasizing normalization and optimization techniques. It discusses transaction management, ACID properties, concurrency control, and advanced SQL techniques such as subqueries, triggers, and stored procedures. Additionally, it outlines backup and recovery methods, highlighting different recovery models and their applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Chapter 18: Databases (Extended Concepts)

1. Advanced Database Models


1.1 Relational Model (Advanced)
The Relational Model is a powerful abstraction used to store data in tables
(relations), with strict rules on how data should be stored and how relationships
are formed.

Extended Concepts of the Relational Model:


Normalization: In-depth normalization is crucial for database design and involves
transforming complex tables into simpler ones by eliminating redundancy.

Boyce-Codd Normal Form (BCNF): A stricter version of 3NF. A table is in BCNF if


every determinant is a candidate key. This removes more anomalies and ensures
greater data integrity.

Fourth Normal Form (4NF): Deals with multi-valued dependencies. A table is in 4NF
if it has no multi-valued dependencies, ensuring no redundancy in rows due to such
dependencies.

Fifth Normal Form (5NF): Deals with join dependencies and ensures that tables are
free from redundancy arising from decomposing information into more than one table.

Example:

1NF: A table with students and their courses might have multiple courses in one
column. This would violate 1NF.

2NF: Remove partial dependencies (attributes that depend on part of a composite


primary key).

3NF: Remove transitive dependencies (where a non-key attribute depends on another


non-key attribute).

BCNF: Ensure that no attribute is dependent on anything other than a candidate key.

1.2 Entity-Relationship (ER) Model


The ER Model is a conceptual framework for database design. It uses diagrams to
represent data and their relationships.

Extended Concepts:
Generalization: The process of abstracting common characteristics from multiple
entities to create a higher-level entity. For example, the entities Car and
Motorcycle might be generalized into a parent Vehicle entity.

Specialization: The reverse process, where an entity is divided into more specific
entities based on some distinguishing characteristics. For example, Person might be
specialized into Student and Teacher.

Participation Constraints: Defines the extent of involvement of an entity in a


relationship. It can be total (every instance of the entity must participate) or
partial (some instances may not participate).

Example: Consider an entity Employee having a relationship Works_In with an entity


Department. If every employee works in a department, this relationship is of total
participation.

2. Database Design
2.1 Advanced Database Design and Optimization
The design of a database is crucial for ensuring performance, scalability, and
integrity. After creating an ER diagram and translating it into relational tables,
further considerations are needed to improve efficiency and usability.

Techniques for Database Optimization:


Indexing: Indexing speeds up data retrieval by creating an ordered structure based
on the column(s) indexed. For example, an index on a Student_ID column in the
Students table will make searches by Student_ID faster.

Types of Indexes:

Primary Index: Created on the primary key.

Secondary Index: Created on other columns that are frequently queried.

Unique Index: Ensures that no two rows have the same value in the indexed column.

Denormalization: Sometimes, denormalizing a database (introducing redundancy) can


speed up read-heavy operations at the cost of slower writes. For example, if
querying for the total sales in a store requires joining several tables, storing
the total sales in one table might speed up queries.

Advanced Querying Techniques:


Join Types:

INNER JOIN: Returns records that have matching values in both tables.

LEFT JOIN (OUTER JOIN): Returns all records from the left table, and the matched
records from the right table, or NULL if no match.

RIGHT JOIN (OUTER JOIN): Similar to LEFT JOIN but returns all records from the
right table.

FULL OUTER JOIN: Combines the results of both LEFT and RIGHT joins.

CROSS JOIN: Returns the Cartesian product of two tables (every combination of
rows).

Example:

sql
Copy
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
2.2 Advanced Relationships in Database Design
Ternary Relationships: Involve three entities rather than just two. For example, in
a relationship between Customer, Product, and Salesperson, a ternary relationship
can model which salesperson sold which product to which customer.

Example:

plaintext
Copy
Customer --< Sales >-- Product
A ternary relationship can represent complex scenarios where data depends on
multiple entities.

3. Transactions and Concurrency Control


3.1 Transaction Management
A transaction is a sequence of database operations that are performed as a single
unit of work. A transaction must either be fully completed (commit) or fully undone
(rollback). Transactions are essential for maintaining data integrity.

Extended Concepts:
ACID Properties:

Atomicity: A transaction is all-or-nothing.

Consistency: A transaction takes the database from one consistent state to another.

Isolation: The intermediate state of a transaction is not visible to other


transactions.

Durability: Once a transaction is committed, the changes are permanent, even in the
event of a failure.

Isolation Levels:

Read Uncommitted: Allows transactions to see uncommitted changes from other


transactions.

Read Committed: Only committed changes are visible to other transactions.

Repeatable Read: Ensures that once a transaction reads a record, no other


transaction can modify it.

Serializable: The strictest level of isolation; ensures transactions are executed


serially.

Example:

sql
Copy
BEGIN TRANSACTION;
UPDATE Inventory SET StockQuantity = StockQuantity - 1 WHERE ProductID = 101;
COMMIT;
3.2 Concurrency Control
Concurrency control is vital for maintaining the integrity of a database when
multiple transactions occur simultaneously. There are different mechanisms, such as
locking and timestamping, to prevent conflicts.

Types of Locks:
Exclusive Lock: A transaction has exclusive access to the resource, and no other
transaction can access it.

Shared Lock: Multiple transactions can read the resource, but no transaction can
modify it.

Deadlock: A situation where two or more transactions are waiting indefinitely for
each other to release resources, which can be resolved by techniques like deadlock
detection or timeouts.

4. Advanced SQL Techniques


4.1 Subqueries and Nested Queries
A subquery is a query embedded inside another query. It is used to perform
operations like filtering, aggregation, or finding matching records.
Scalar Subquery: Returns a single value.

sql
Copy
SELECT Name FROM Employees WHERE Salary = (SELECT MAX(Salary) FROM Employees);
Correlated Subquery: Refers to columns from the outer query.

sql
Copy
SELECT e.Name
FROM Employees e
WHERE e.Salary > (SELECT AVG(Salary) FROM Employees WHERE Department =
e.Department);
4.2 Triggers and Stored Procedures
Triggers: Are automated actions triggered by certain database events (insert,
update, delete).

Example Trigger: Automatically log any changes made to the Employees table.

sql
Copy
CREATE TRIGGER log_employee_update
AFTER UPDATE ON Employees
FOR EACH ROW
INSERT INTO AuditLog (Action, OldSalary, NewSalary, ChangeDate)
VALUES ('Salary Update', OLD.Salary, NEW.Salary, NOW());
Stored Procedures: Are precompiled SQL statements that can be executed as a single
command. They can accept parameters and improve performance by reducing repetitive
SQL execution.

Example Stored Procedure:

sql
Copy
CREATE PROCEDURE GetEmployeeInfo(IN emp_id INT)
BEGIN
SELECT Name, Department, Salary FROM Employees WHERE EmployeeID = emp_id;
END;
5. Backup and Recovery in Depth
5.1 Types of Database Backups:
Point-in-Time Recovery: Recover a database to a specific moment in time, typically
used after an unintended modification or data loss.

Continuous Archiving: Automatically archives changes to the database, allowing for


near-continuous recovery.

5.2 Advanced Recovery Models:


Full Recovery Model: Every transaction is fully logged, allowing point-in-time
recovery.

Simple Recovery Model: Only the changes that are necessary for restoring the
database to a consistent state are logged.

Bulk-Logged Recovery Model: Similar to the full model but optimized for bulk
operations like large inserts.

You might also like