Lecture 5. Some solutions on the written examination: Primary key: Unique identifier for each row in a table. Not allowed to be null. Cascade update:

Slides:



Advertisements
Similar presentations
Concurrency Control WXES 2103 Database. Content Concurrency Problems Concurrency Control Concurrency Control Approaches.
Advertisements

CSC271 Database Systems Lecture # 32.
Transaction Management Transparencies
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
Data and Database Administration Chapter 12. Outline What is Concurrency Control? Background Serializability  Locking mechanisms.
1 Chapter 2 Database Environment Transparencies © Pearson Education Limited 1995, 2005.
Chapter 2 Database Environment.
10 1 Chapter 10 Transaction Management and Concurrency Control Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Transaction Management and Concurrency Control
Transaction Management and Concurrency Control
Manajemen Basis Data Pertemuan 4 Matakuliah: M0264/Manajemen Basis Data Tahun: 2008.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Chapter 17: Transaction Management
What is a Transaction? Logical unit of work
Transaction Management
1 Minggu 8, Pertemuan 15 Transaction Management Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Chapter 8 Security Transparencies © Pearson Education Limited 1995, 2005.
Chapter 2 Database Environment Pearson Education © 2014.
1 Chapter 2 Database Environment. 2 Objectives of Three-Level Architecture u All users should be able to access same data u User’s view immune to changes.
9 Chapter 9 Transaction Management and Concurrency Control Hachim Haddouti.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Lecture Two Database Environment Based on Chapter Two of this book:
Transaction Management and Concurrency Control
1 Chapter 2 Database Environment. 2 Chapter 2 - Objectives u Purpose of three-level database architecture. u Contents of external, conceptual, and internal.
Chapter 19 Security Transparencies. 2 Chapter 19 - Objectives Scope of database security. Why database security is a serious concern for an organization.
Database Environment 1.  Purpose of three-level database architecture.  Contents of external, conceptual, and internal levels.  Purpose of external/conceptual.
© Pearson Education Limited, Chapter 5 Database Administration and Security Transparencies.
1 Chapter 6 : Transaction Management Pearson Education © 2009.
Transaction Processing Concepts
Security and Transaction Nhi Tran CS 157B - Dr. Lee Fall, 2003.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
Chapterb19 Transaction Management Transaction: An action, or series of actions, carried out by a single user or application program, which reads or updates.
Transaction Management, Concurrency Control and Recovery Chapter 20 1.
1 Chapter 20 Transaction Management Transparencies Last Updated: 17 th March 2011 By M. Arief
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
11/7/2012ISC329 Isabelle Bichindaritz1 Transaction Management & Concurrency Control.
8/31/2012ISC329 Isabelle Bichindaritz1 Database Environment.
Database Environment Chapter 2. Data Independence Sometimes the way data are physically organized depends on the requirements of the application. Result:
Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.
Bayu Adhi Tama, M.T.I 1 © Pearson Education Limited 1995, 2005.
Database Environment Session 2 Course Name: Database System Year : 2013.
II.I Selected Database Issues: 2 - Transaction ManagementSlide 1/20 1 II. Selected Database Issues Part 2: Transaction Management Lecture 4 Lecturer: Chris.
1 Chapter 1 Introduction to Databases Transparencies.
CSC 240 (Blum)1 Database Transactions. CSC 240 (Blum)2 Transaction  A transaction is an interaction between a user (or application) and a database. A.
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
Transaction Management and Concurrent Control
9 1 Chapter 9_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
NOEA/IT - FEN: Databases/Transactions1 Transactions ACID Concurrency Control.
Chapter 2 Database Environment.
10 1 Chapter 10_B Concurrency Control Database Systems: Design, Implementation, and Management, Rob and Coronel.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
10 Transaction Management and Concurrency Control MIS 304 Winter 2005.
1 Database Environment. 2 Objectives of Three-Level Architecture u All users should be able to access same data. u A user’s view is immune to changes.
3 Database Systems: Design, Implementation, and Management CHAPTER 9 Transaction Management and Concurrency Control.
1 Chapter 2 Database Environment Pearson Education © 2009.
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
9 1 Chapter 9 Transaction Management and Concurrency Control Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
SYSTEMS IMPLEMENTATION TECHNIQUES TRANSACTION PROCESSING DATABASE RECOVERY DATABASE SECURITY CONCURRENCY CONTROL.
Transaction Management and Concurrency Control
Transaction Management Transparencies
Chapter 2 Database Environment.
Chapter 10 Transaction Management and Concurrency Control
Database Environment Transparencies
Database Security Transactions
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Transaction management
Chapter 2 Database Environment Pearson Education © 2014.
Chapter 2 Database Environment Pearson Education © 2009.
Presentation transcript:

Lecture 5

Some solutions on the written examination: Primary key: Unique identifier for each row in a table. Not allowed to be null. Cascade update: A constraint for a relationship that allows updates of a primary key. If you change the primary key – all the foreign keys on the other side of a relationship is updated automatically. Null: is not the same as 0 because 0 is a value. Null value means ”nothing at all” or ”not applicable”. View: Its a virtual table based on an sql-question to serve as tailormade information for an application or user. Good to present views (belongs to the external layer) because of changes in the logic layer). Could also act as a security mechanism to hide some colums or so. Normalization: Is a technique used to validate your database design from a couple of normalization rules. The most usual normalization rules is 1NF, 2NF, 3NF and BCNF. The rules are used to check that no redundant information or inconsistent information exists in the database. This means that you can do updates, insertions and deltete operations without any problem.

Objectives of Three-Level Architecture All users should be able to access same data. A user’s view is immune to changes made in other views. Users should not need to know physical database storage details. DBA should be able to change database storage structures without affecting the users’ views. Internal structure of database should be unaffected by changes to physical aspects of storage. DBA should be able to change conceptual structure of database without affecting all users. 3

ANSI-SPARC Three-Level Architecture 4

External Level Users’ view of the database. Describes that part of database that is relevant to a particular user. Conceptual Level Community view of the database. Describes what data is stored in database and relationships among the data. Internal Level Physical representation of the database on the computer. Describes how the data is stored in the database. 5

Differences between Three Levels of ANSI-SPARC Architecture 6

Data Independence Logical Data Independence Refers to immunity of external schemas to changes in conceptual schema. Conceptual schema changes (e.g. addition/removal of entities). Should not require changes to external schema or rewrites of application programs. Physical Data Independence Refers to immunity of conceptual schema to changes in the internal schema. Internal schema changes (e.g. using different file organizations, storage structures/devices). Should not require change to conceptual or external schemas. 7

Data Independence and the ANSI- SPARC Three-Level Architecture 8

Database Languages Data Definition Language (DDL) Allows the DBA or user to describe and name entities, attributes, and relationships required for the application plus any associated integrity and security constraints. Data Manipulation Language (DML) Provides basic data manipulation operations on data held in the database. Procedural DML allows user to tell system exactly how to manipulate data. Non-Procedural DML allows user to state what data is needed rather than how it is to be retrieved. Fourth Generation Languages (4GLs) 9

Constraint on relationships Cascade delete The relation below try to describe the structure of an order. Can an orderhead exist without a row? If you delete a certain row in orderhead…what happens? Cascade update If you update oredernr in orderhead…what happens? OrderheadOrderrow * 1 Ordernr Date custnr Ordernr Partnr Quantity orderprice

What is a stored procedure? How its working? SQL server has a language called transact SQL and its used to create modules of logic database actions. It is stored in database with a name to call when you need it. An example of executing a stored procedure to create a new customer: EXEC sp_newcustomer (’23’,’Jesper’, ’Hakeröd’,…) More practise on this in laboratory work 2.

-- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[uspNewCustomer] as as as as as as as nvarchar(10)) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insertion of the customer INSERT INTO CUSTOMER (CustomerID, firstname, surename, address, cellular, , END Example of a stored procedure

Exemple: Security in SQL Server

16 Database Security Data is a valuable resource that must be strictly controlled and managed, as with any corporate resource. Part or all of the corporate data may have strategic importance and therefore needs to be kept secure and confidential. Mechanisms that protect the database against intentional or accidental threats. Security considerations do not only apply to the data held in a database. Breaches of security may affect other parts of the system, which may in turn affect the database.

17 Database Security Involves measures to avoid: – Theft and fraud – Loss of confidentiality (secrecy) – Loss of privacy – Loss of integrity – Loss of availability

19 Database Security Threat – Any situation or event, whether intentional or unintentional, that will adversely affect a system and consequently an organization.

20 Summary of Threats to Computer Systems

21 Typical Multi-user Computer Environment

22 Countermeasures – Computer-Based Controls Concerned with physical controls to administrative procedures and includes: – Authorization – Access controls – Views – Backup and recovery – Integrity – Encryption – RAID technology

23 Transaction Support Transaction Action, or series of actions, carried out by user or application, which reads or updates contents of database. Logical unit of work on the database. Application program is series of transactions with non- database processing in between. Transforms database from one consistent state to another, although consistency may be violated during transaction.

24 Example Transaction

25 Transaction Support Can have one of two outcomes: – Success - transaction commits and database reaches a new consistent state. – Failure - transaction aborts, and database must be restored to consistent state before it started. – Such a transaction is rolled back or undone. Committed transaction cannot be aborted. Aborted transaction that is rolled back can be restarted later.

26 State Transition Diagram for Transaction

27 Properties of Transactions Four basic (ACID) properties of a transaction are: Atomicity ‘All or nothing’ property. ConsistencyMust transform database from one consistent state to another. Isolation Partial effects of incomplete transactions should not be visible to other transactions. DurabilityEffects of a committed transaction are permanent and must not be lost because of later failure.

28 Concurrency Control Process of managing simultaneous operations on the database without having them interfere with one another. Prevents interference when two or more users are accessing database simultaneously and at least one is updating data. Although two transactions may be correct in themselves, interleaving of operations may produce an incorrect result.

29 Need for Concurrency Control Three examples of potential problems caused by concurrency: – Lost update problem. – Uncommitted dependency problem. – Inconsistent analysis problem.

30 Lost Update Problem Successfully completed update is overridden by another user. T 1 withdrawing £10 from an account with bal x, initially £100. T 2 depositing £100 into same account. Serially, final balance would be £190.

31 Lost Update Problem Loss of T 2 ’s update avoided by preventing T 1 from reading bal x until after update.

32 Uncommitted Dependency Problem Occurs when one transaction can see intermediate results of another transaction before it has committed. T 4 updates bal x to £200 but it aborts, so bal x should be back at original value of £100. T 3 has read new value of bal x (£200) and uses value as basis of £10 reduction, giving a new balance of £190, instead of £90.

33 Uncommitted Dependency Problem Problem avoided by preventing T 3 from reading bal x until after T 4 commits or aborts.

34 Inconsistent Analysis Problem Occurs when transaction reads several values but second transaction updates some of them during execution of first. Sometimes referred to as dirty read or unrepeatable read. T 6 is totaling balances of account x (£100), account y (£50), and account z (£25). Meantime, T 5 has transferred £10 from bal x to bal z, so T 6 now has wrong result (£10 too high).

35 Inconsistent Analysis Problem Problem avoided by preventing T 6 from reading bal x and bal z until after T 5 completed updates.

36 Serializability Objective of a concurrency control protocol is to schedule transactions in such a way as to avoid any interference. Could run transactions serially, but this limits degree of concurrency or parallelism in system. Serializability identifies those executions of transactions guaranteed to ensure consistency.

37 Concurrency Control Techniques Two basic concurrency control techniques: – Locking, – Timestamping. Both are conservative approaches: delay transactions in case they conflict with other transactions. Optimistic methods assume conflict is rare and only check for conflicts at commit.

38 Locking Transaction uses locks to deny access to other transactions and so prevent incorrect updates. Most widely used approach to ensure serializability. Generally, a transaction must claim a shared (read) or exclusive (write) lock on a data item before read or write. Lock prevents another transaction from modifying item or even reading it, in the case of a write lock.

39 Locking - Basic Rules If transaction has shared lock on item, can read but not update item. If transaction has exclusive lock on item, can both read and update item. Reads cannot conflict, so more than one transaction can hold shared locks simultaneously on same item. Exclusive lock gives transaction exclusive access to that item.

40 Two-Phase Locking (2PL) Transaction follows 2PL protocol if all locking operations precede first unlock operation in the transaction. Two phases for transaction: – Growing phase - acquires all locks but cannot release any locks. – Shrinking phase - releases locks but cannot acquire any new locks.

41 Preventing Lost Update Problem using 2PL Pearson Education © 2009

42 Preventing Uncommitted Dependency Problem using 2PL

43 Preventing Inconsistent Analysis Problem using 2PL

44 Deadlock An impasse that may result when two (or more) transactions are each waiting for locks held by the other to be released.

45 Deadlock Only one way to break deadlock: abort one or more of the transactions. Deadlock should be transparent to user, so DBMS should restart transaction(s). Three general techniques for handling deadlock: – Timeouts. – Deadlock prevention. – Deadlock detection and recovery.

46 Timeouts Transaction that requests lock will only wait for a system-defined period of time. If lock has not been granted within this period, lock request times out. In this case, DBMS assumes transaction may be deadlocked, even though it may not be, and it aborts and automatically restarts the transaction.

47 Deadlock Prevention DBMS looks ahead to see if transaction would cause deadlock and never allows deadlock to occur. Could order transactions using transaction timestamps: – Wait-Die - only an older transaction can wait for younger one, otherwise transaction is aborted (dies) and restarted with same timestamp.

48 Deadlock Prevention – Wound-Wait - only a younger transaction can wait for an older one. If older transaction requests lock held by younger one, younger one is aborted (wounded).