Latihan Lock.

Slides:



Advertisements
Similar presentations
Day 9. SELECT INSERT UPDATE DELETE » The standard UPDATE statement. UPDATE table SET field1=val1, field2=val2 WHERE condition » Multiple table UPDATE.
Advertisements

Accessing data Transactions. Agenda Questions from last class? Transactions concurrency Locking rollback.
MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Pertemuan ke 2 Tipe data & ERD Kurniawan Eka Permana.
Transaction Processing. Objectives After completing this lesson, you should be able to do the following: –Define transactions effectively for an application.
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
At the end of this lesson, you should be able to: Describe each DML statement Insert rows into a table Update rows in a table Delete rows from a table.
Transactions Dr. Charles Severance
9 Copyright © 2009, Oracle. All rights reserved. Managing Data Concurrency.
Databases & Consistency. Database Relational databases : dominant information storage/retrieval system.
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
1 CSE 480: Database Systems Lecture 23: Transaction Processing and Database Recovery.
DBMS Transactions and Rollback Recovery Helia / Martti Laiho.
MySQL. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn The main subsystems in MySQL architecture The different storage.
Introduction to Internet Databases MySQL Database System Database Systems.
9 Copyright © 2007, Oracle. All rights reserved. Managing Data and Concurrency.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Databases MIS 21. Some database terminology  Database: integrated collection of data  Database Management System (DBMS): environment that provides mechanisms.
8 Copyright © 2005, Oracle. All rights reserved. Managing Data.
CMPE 226 Database Systems October 7 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
INLS 623– T RANSACTIONS Instructor: Jason Carter.
1 Announcements Reading for next week: Chapter 4 Your first homework will be assigned as soon as your database accounts have been set up.  Expect an .
Transactions, Roles & Privileges Oracle and ANSI Standard SQL Lecture 11.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
CREATE TABLE ARTIST ( ArtistID int NOT NULL IDENTITY (1,1), Namechar(25) NOT NULL, TEXT ERROR Nationality char (30) NULL, Birthdate numeric (4,0) NULL,
Oracle & SQL. Oracle Data Types Character Data Types: Char(2) Varchar (20) Clob: large character string as long as 4GB Bolb and bfile: large amount of.
1 Stored Procedures in MySQL Part I. 2 Objectives SQL Vs. MySQL SP MySQL SP Parameters MySQL SP Control Structures.
A Guide to MySQL 6. 2 Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT command.
A Guide to SQL, Sixth Edition 1 Chapter 5 Updating Data.
1 Transaction Processing. 2 Pendahuluan In most large database systems, many users and application programs will be (and must be) accessing the database.
CMPE 226 Database Systems March 15 Class Meeting Department of Computer Engineering San Jose State University Spring 2016 Instructor: Ron Mak
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
CC ICT-SUD Installation and configuration
CCT395, Week 6 Implementing a Database with SQL and a Case Study Exercise This presentation is licensed under Creative Commons Attribution License, v.
SQL error diagnostics, Get Diagnostics and well designed Transactions
3 A Guide to MySQL.
Managing Concurrency in Web Applications
Database Access with SQL
Transactions Dr. Charles Severance
Databases & Consistency
Understanding SQL Statements
Postgres MySQL Bakeoff
Referential Integrity MySQL
LAB: Web-scale Data Management on a Cloud
Introduction to Oracle9i: SQL
Error Handling Summary of the next few pages: Error Handling Cursors.
Transaction Properties
Databases & Consistency
עיבוד תנועות בסביבת SQL Transaction Processing
මොඩියුල විශ්ලේෂණය Transactions කළමනාකරණය.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
مقدمة في قواعد البيانات
What we’ll be doing Back to Basics Read Consistency Write Consistency.
Objectives Define and describe transactions
Using PHP with MySQL Part 3
MySQL Database System Installation Overview SQL summary
Data Access Layer (Con’t) (Overview)
Updating Databases With Open SQL
MySQL Database System Installation Overview SQL summary
Updating Databases With Open SQL
Presentation transcript:

Latihan Lock

Transaksi - BEGIN transaksi COMMIT; - ROLLBACK; (utk membatalkan)

Transaksi buatlah tabel rekening dan isikan datanya CREATE TABLE rekening (norek char(10) PRIMARY KEY, nama varchar(30), saldo numeric(10.2)); DESCRIBE mhs; INSERT INTO rekening VALUES (‘111’,’Bapak’,5000000); INSERT INTO rekening VALUES (‘222’,’anak’,1000000); SELECT * FROM rekening; buatlah transaksi transfer uang 1 juta dari Bapak ke anak

Transaksi Jawaban: BEGIN; UPDATE rekening SET saldo=saldo-1000000 WHERE nama=‘Bapak’;UPDATE rekening SET saldo=saldo+1000000 WHERE nama=‘anak’; COMMIT; Latihan: UPDATE rekening SET saldo=saldo-1000000 WHERE nama=‘Bapak’; ROLLBACK;

A mysql> CREATE TABLE t (i INT) ENGINE = InnoDB; Query OK, 0 rows affected (1.07 sec) mysql> INSERT INTO t (i) VALUES(1); Query OK, 1 row affected (0.09 sec) mysql> START TRANSACTION; Query OK, 0 rows affected (0.00 sec) mysql> SELECT * FROM t WHERE i = 1 LOCK IN SHARE MODE; 1 row in set (0.10 sec)

B mysql> START TRANSACTION; Query OK, 0 rows affected (0.00 sec) mysql> DELETE FROM t WHERE i = 1;

A mysql> DELETE FROM t WHERE i = 1; ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction Sama-sama minta exclusive lock jadi deadlock

Consistent Read

A mysql> BEGIN; Query OK, 0 rows affected (0.00 sec) mysql> SELECT MAX(i) FROM t; mysql> INSERT INTO t(i) VALUES (4); Query OK, 1 row affected (0.00 sec)

B mysql> BEGIN; Query OK, 0 rows affected (0.00 sec) mysql> SELECT MAX(i) FROM t; mysql> INSERT INTO t(i) VALUES(4); Query OK, 1 row affected (0.00 sec) mysql> COMMIT; Query OK, 0 rows affected (0.00 sec)

A mysql> COMMIT; Query OK, 0 rows affected (0.00 sec) mysql> SELECT * FROM t;

A mysql> DELETE FROM t WHERE i=4; Query OK, 2 rows affected (0.00 sec) mysql> SELECT * FROM t;

A mysql> SELECT * FROM t; mysql> BEGIN; Query OK, 0 rows affected (0.00 sec) mysql> SELECT MAX(i) FROM t FOR UPDATE; mysql> INSERT INTO t(i) VALUES (4); Query OK, 1 row affected (0.00 sec)

B mysql> SELECT MAX(i) FROM t FOR UPDATE; mysql> COMMIT; Query OK, 0 rows affected (0.00 sec)

B mysql> SELECT MAX(i) FROM t FOR UPDATE; mysql> INSERT INTO t(i) VALUES(5); Query OK, 1 row affected (0.00 sec) mysql> COMMIT; Query OK, 0 rows affected (0.01 sec) mysql> SELECT * FROM t;

READ LOCK A mysql> BEGIN; Query OK, 0 rows affected (0.00 sec) mysql> SELECT MAX(i) FROM t LOCK IN SHARE MODE;

B mysql> UPDATE t SET i = 55 WHERE i=5;

A mysql> COMMIT; Query OK, 0 rows affected (0.00 sec)

B mysql> UPDATE t SET i = 55 WHERE i=5; Query OK, 0 rows affected (6.95 sec) Rows matched: 0 Changed: 0 Warnings: 0 mysql> UPDATE t SET i = 55 WHERE i=5; Query OK, 1 row affected (43.30 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT * FROM t;