0% found this document useful (0 votes)
3 views

Advaced DB Ch1

The document outlines the course 'Advanced Database Systems' taught by Dr. Bahman Arasteh, covering key topics such as database management systems (DBMS), types of DBMS, database design, normalization, SQL query language, and transaction concepts. It includes grading policies, textbooks, and detailed explanations of database architecture and transaction properties. The course emphasizes the importance of ACID properties in transactions to ensure data integrity and consistency.

Uploaded by

mariamalsedawi3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Advaced DB Ch1

The document outlines the course 'Advanced Database Systems' taught by Dr. Bahman Arasteh, covering key topics such as database management systems (DBMS), types of DBMS, database design, normalization, SQL query language, and transaction concepts. It includes grading policies, textbooks, and detailed explanations of database architecture and transaction properties. The course emphasizes the importance of ACID properties in transactions to ensure data integrity and consistency.

Uploaded by

mariamalsedawi3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 50

Advanced Database Systems

Bahman Arasteh
(Associate Prof., Software Engineering)
Department of Software Engineering,
Istinye University
E-mail: [email protected]

1 Advanced Database- Dr. Arasteh


Textbooks
• "Database System Concepts", Sixth Edition, Abraham
Silberschatz, Henry F. Korth, S. Sudarshan

2 Advanced Database- Dr. Arasteh


Grading Policy
• Projects and Assignments: 25%
• Midterm Exam:25%
• Final Exam:50%
• Extra Marks:
– Draft of a Paper: 10%
– Submission of the Paper: 5%

3 Advanced Database- Dr. Arasteh


Today’s Goals

Overview of Databases
and
Transaction Concept

4
Advanced Database- Dr. Arasteh
Overview of Databases

5
Advanced Database- Dr. Arasteh
What is Database Systems?
• A Database Management System (DBMS) is software that enables
users to create, manage, and manipulate databases efficiently.
• It provides a systematic way to store, retrieve, update, and delete
data while ensuring security, consistency, and integrity.
• Key Functions of a DBMS:
1. Data Storage
2. Data Manipulation (Allows inserting, updating, and deleting data)
3. Data Security and Data Integrity.
4. Concurrency Control.
5. Backup & Recovery.

6 Advanced Database- Dr. Arasteh


Types of DBMS
1. Hierarchical DBMS – Data is structured in a tree-like
hierarchy.
2. Network DBMS – Uses a graph structure to represent
relationships.
3. Relational DBMS (RDBMS) – Uses tables (relations) to
store data (e.g., MySQL, PostgreSQL, Oracle).
4. Object-Oriented DBMS – Stores data in objects, similar to
object-oriented programming.
5. NoSQL DBMS – Designed for handling unstructured or
semi-structured data (e.g., MongoDB, Cassandra).

7 Advanced Database- Dr. Arasteh


Network Database Model

8 Advanced Database- Dr. Arasteh


Relational Model
• All the data is stored in various tables.
• Example of tabular data in the relational model

Columns

Rows

9 Advanced Database- Dr. Arasteh


NO SQL Databases

10 Advanced Database- Dr. Arasteh


RDBMS Comparison

11 Advanced Database- Dr. Arasteh


Which RDBMS is Fastest?

• For Read-Heavy Workloads: PostgreSQL & IBM Db2


• For Write-Heavy Workloads: Oracle & Microsoft SQL Server
• For Web Applications: MySQL & MariaDB
• For Large-Scale Enterprise: Oracle & IBM Db2

12 Advanced Database- Dr. Arasteh


Database Design
The process of designing the general structure of the database:

• Logical Design – Deciding on the database schema. Database design


requires that we find a “good” collection of relation schemas.
– Business decision – What attributes should we record in the
database?
– Computer Science decision – What relation schemas should we
have and how should the attributes be distributed among the
various relation schemas?
• Physical Design – Deciding on the physical layout of the database

13 Advanced Database- Dr. Arasteh


Database Design
Entity Diagram for University Database

14 Advanced Database- Dr. Arasteh


Types of Relationship in the ER

• Express the number of entities to which another entity can be associated via
a relationship set.
• Most useful in describing binary relationship sets.
• For a binary relationship set the mapping cardinality must be one of the
following types:
– One to one
– One to many
– Many to one
– Many to many

15 Advanced Database- Dr. Arasteh


Database Normalization
• A large database defined as a single relation may result in
data duplication. This repetition of data may result in:
– Making relations very large.
– It isn't easy to maintain and update data as it would involve
searching many records in relation.
– Wastage and poor utilization of disk space and resources.
– The likelihood of errors and inconsistencies increases.

– Normalization is used to minimize the redundancy from a


relation or set of relations.
– Normalization divides the larger table into smaller and links
them using relationships.
– The normal form is used to reduce redundancy from the
database table.

16 Advanced Database- Dr. Arasteh


Database Normalization cont.

17 Advanced Database- Dr. Arasteh


Database Normalization cont.

18 Advanced Database- Dr. Arasteh


Database Normalization cont.
• In order to make the table satisfy the third normal form, the table
must be in the second and first normal forms. Then, there is an
additional rule, the table has no transitive dependency.

19
Advanced Database- Dr. Arasteh
SQL Query Language
• SQL query language is nonprocedural. A query takes as input several tables
(possibly only one) and always returns a single table.
• Example to find all instructors in Comp. Sci. dept
select name
from instructor
where dept_name = 'Comp. Sci.'
• SQL is NOT a Turing machine equivalent language
• To be able to compute complex functions SQL is usually embedded in some
higher-level language
• Application programs generally access databases through one of
– Language extensions to allow embedded SQL
– Application program interface (e.g., ODBC/JDBC) which allow SQL queries
to be sent to a database

20 Advanced Database- Dr. Arasteh


SQL Example
• Find the average salary of instructors in each department
– select dept_name, avg (salary) as avg_salary
from instructor
group by dept_name;

21 Advanced Database- Dr. Arasteh


Database Architecture
• Centralized databases
– One to a few cores, shared memory
• Client-server,
– One server machine executes work on behalf of multiple client
machines.
• Parallel databases
– Many core shared memory
– Shared disk
– Shared nothing
• Distributed databases
– Geographical distribution
– Schema/data heterogeneity

22 Advanced Database- Dr. Arasteh


Client-server Database
• A Client-Server Database is a type of database architecture where the database
system is divided into two components:
1. Client – The front-end application that interacts with users, sends queries, and
displays results.
2. Server – The back-end system that processes client requests, manages data storage,
and ensures security and integrity.
• How It Works:
• The client sends a request (e.g., SQL query) to the server.
• The server processes the request, retrieves the necessary data, and sends the
response back to the client.
• The client then presents the data in a readable format.

23 Advanced Database- Dr. Arasteh


Parallel Databases
• A Parallel Database is a type of database system that uses multiple
processors and storage devices to perform operations
simultaneously.
• Key Features of Parallel Databases:
– Parallel Processing: Multiple queries or operations are executed at the same
time.
– High Performance: Reduces query execution time by distributing workloads.
– Scalability: Can handle large amounts of data and increasing user demands.
– Fault Tolerance: Some parallel databases offer redundancy to improve reliability.

24 Advanced Database- Dr. Arasteh


Distributed Databases
• A Distributed Database (DDB) is a database system where data is
stored across multiple physical locations, which can be on different
computers or servers connected via a network.
• Key Characteristics of Distributed Databases:
– Data Distribution – Data is stored across multiple sites or nodes.
– Transparency – Users interact with the system as if it were a single
database.
– Autonomy – Each site may have its own DBMS and control over local
data.
– Concurrency Control – Ensures data consistency across different
locations.

25 Advanced Database- Dr. Arasteh


Distributed Databases

26 Advanced Database- Dr. Arasteh


Transaction Concept

27
Advanced Database- Dr. Arasteh
Transaction Concept
• Definition:
– A transaction is a unit of program execution that accesses
and possibly updates various data items.
– A transaction comprises a unit of work performed within
a database management system.
– A transaction is a logical unit that is independently
executed for data retrieval or updates.
– A series of data manipulation statements that must either
fully complete or fully fail, leaving the database in a
consistent state.

28 Advanced Database- Dr. Arasteh


Transaction Concept
• E.g. Transaction to transfer $50 from account A to account B:

1.read(A)
2.A := A – 50
3.write(A)
4.read(B)
5.B := B + 50
6.write(B)

29 Advanced Database- Dr. Arasteh


Transaction Example in MSSQL
• Transaction Example in MSSQL

30 Advanced Database- Dr. Arasteh


Transaction Concept
• Characteristics:
– A transaction is a program or part of a program.
– A transaction includes start and end points.
– A transaction has to either happen in full, or not at all.
– …

31 Advanced Database- Dr. Arasteh


Transaction Concept
• Example:
• You need to transfer 100 dollar from account A to account B. You
can either do:
1. accountA -= 100;
2. accountB += 100;
or
1. accountB += 100;
2. accountA -= 100;
• If something goes wrong between the first and the second operation in the
pair you have a problem:
– either 100 dollar have disappeared or they have appeared out of
nowhere.

32 Advanced Database- Dr. Arasteh


Transaction Concept
• A transaction is a mechanism that allows you to mark a group of operations
and execute them in such a way that either they all execute (commit) or the
system state will be as if they have not started to execute at all (rollback).

1.beginTransaction;
2.accountB += 100;
3.accountA -= 100;
4.commitTransaction;

• This transaction will either transfer 100 dollar or leave both account in the
initial state.

33 Advanced Database- Dr. Arasteh


Transaction Properties
– A transaction is a program or part of a program.
– A transaction includes start and end points.
– A transaction has to either happen in full, or not at all.
– Transactions are completed by COMMIT or ROLLBACK
SQL statements.
– The ACID acronym defines the properties of a database
transaction.
• ACID = Atomicity, Consistency, Isolation, Durability

34 Advanced Database- Dr. Arasteh


Transaction Properties
To preserve the integrity of data the database system must ensure:
•Atomicity. Either all operations of the transaction are properly reflected in
the database or none are.
•Consistency. Execution of a transaction in isolation preserves the
consistency of the database.
•Isolation. Although multiple transactions may execute concurrently, each
transaction must be unaware of other concurrently executing transactions.
Intermediate transaction results must be hidden from other concurrently
executed transactions.
– That is, for every pair of transactions Ti and Tj, it appears to Ti that
either Tj, finished execution before Ti started, or Tj started execution
after Ti finished.
•Durability. After a transaction completes successfully, the changes it has
made to the database persist, even if there are system failures.
35 Advanced Database- Dr. Arasteh
Transaction Properties
• Transaction to transfer $50 from account A to account B:
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
• Consistency requirement in above example:
– the sum of A and B is unchanged by the execution of the transaction
• In general, consistency requirements include
• Explicitly specified integrity constraints such as primary keys and foreign
keys
• Implicit integrity constraints
– e.g. sum of balances of all accounts, minus sum of loan amounts must
equal value of cash-in-hand
– A transaction must see a consistent database.
– During transaction execution the database may be temporarily inconsistent.
– When the transaction completes successfully the database must be consistent
• Erroneous transaction logic can lead to inconsistency

36 Advanced Database- Dr. Arasteh


Transaction Properties
• Isolation requirement — if between steps 3 and 6, another transaction T2
is allowed to access the partially updated database, it will see an
inconsistent database (the sum A + B will be less than it should be).

T1 T2
1. read(A)
2. A := A – 50
3. write(A)
read(A), read(B), print(A+B)
4. read(B)
5. B := B + 50
6. write(B
• Isolation can be ensured trivially by running transactions serially
– that is, one after the other.
• However, executing multiple transactions concurrently has significant
benefits, as we will see later.

37 Advanced Database- Dr. Arasteh


Transaction State
• Active – the initial state; the transaction stays in this state while it is
executing
• Partially committed – after the final statement has been executed.
• Failed -- after the discovery that normal execution can no longer
proceed.
• Aborted – after the transaction has been rolled back and the
database restored to its state prior to the start of the transaction.
Two options after it has been aborted:
– restart the transaction
• can be done only if no internal logical error
– kill the transaction
• Committed – after successful completion.

38 Advanced Database- Dr. Arasteh


Transaction State

39 Advanced Database- Dr. Arasteh


Transaction Control
• There are following commands used to control
transactions:
– COMMIT: to save the changes.
– ROLLBACK: to rollback the changes.
– SAVEPOINT: creates points within groups of transactions in
which to ROLLBACK
– SET TRANSACTION: Places a name on a transaction.
• Transactional control commands are only used with the
DML commands INSERT, UPDATE and DELETE only.

40 Advanced Database- Dr. Arasteh


Transaction Control
• The COMMIT command is the transactional command
used to save changes invoked by a transaction to the
database.

41 Advanced Database- Dr. Arasteh


Transaction Control
Example: Consider the CUSTOMERS table and the following transaction:

42 Advanced Database- Dr. Arasteh


Transaction Control
As a result, two rows from the table would be deleted and SELECT
statement would produce the following result:

43 Advanced Database- Dr. Arasteh


Transaction Control
• The ROLLBACK command is the transactional
command used to undo transactions that have not
already been saved to the database.
• The ROLLBACK command can only be used to undo
transactions.

44 Advanced Database- Dr. Arasteh


Transaction Control
• Example: Consider the CUSTOMERS table and the following
transaction

45 Advanced Database- Dr. Arasteh


Transaction Control
• As a result, delete operation would not impact the table and
SELECT statement would produce the following result:

46 Advanced Database- Dr. Arasteh


Transaction Control
• The SAVEPOINT Command:
– A SAVEPOINT is a point in a transaction when you can roll the
transaction back to a certain point without rolling back the entire
transaction.
• The RELEASE SAVEPOINT Command:
– The RELEASE SAVEPOINT command is used to remove a
SAVEPOINT that you have created.
• The SET TRANSACTION Command:
– The SET TRANSACTION command can be used to initiate a
database transaction.
– This command is used to specify characteristics for the
transaction that follows.

47 Advanced Database- Dr. Arasteh


Transaction Implimatation
• The transactions can also be handled at SQL level.

48 Advanced Database- Dr. Arasteh


Transaction Implementation
• The transactions can also be handled in .NET
environment using Transactionscope API. .

49 Advanced Database- Dr. Arasteh


End

50 Advanced Database- Dr. Arasteh

You might also like