MSSQL DB - EX09_1

반응형

--10 / 12
--Lock and Isolation Level ( Session 1 )
USE exampledb

--테이블 생성
CREATE TABLE bankaccount
(
 ac_owner nvarchar (10) not null primary key,
 balance money not null
)
INSERT INTO bankaccount VALUES('장동건', 1000)
INSERT INTO bankaccount VALUES('김윤석', 1000)

SELECT * FROM bankaccount

 

UPDATE bankaccount SET balance = 1000

--1.
DBCC USEROPTIONS

BEGIN TRANSACTION

UPDATE bankaccount
SET balance = balance - 500
WHERE ac_owner = '장동건'

UPDATE bankaccount
SET balance = balance + 500
WHERE ac_owner = '김윤석'

ROLLBACK TRANSACTION

--2.
BEGIN TRANSACTION

UPDATE bankaccount
SET balance = balance - 500
WHERE ac_owner = '장동건'

UPDATE bankaccount
SET balance = balance + 500
WHERE ac_owner = '김윤석'

ROLLBACK TRANSACTION

--3.
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN TRANSACTION

SELECT * FROM bankaccount

SELECT * FROM bankaccount

ROLLBACK TRANSACTION

--4.
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
DBCC USEROPTIONS

BEGIN TRANSACTION

UPDATE bankaccount
SET balance = balance - 500
WHERE ac_owner = '장동건'

UPDATE bankaccount
SET balance = balance + 500
WHERE ac_owner = '김윤석'

SELECT * FROM bankaccount

SELECT * FROM bankaccount

ROLLBACK TRANSACTION



 

반응형

'프로그램 > MSSQL SERVER 2008R2' 카테고리의 다른 글

MSSQL DB - EX10  (1) 2010.10.13
MSSQL DB - EX09_2  (0) 2010.10.13
MSSQL DB - EX08  (0) 2010.10.13
MSSQL DB - EX07  (1) 2010.10.08
D20 - EX06 (DECLARE , IF - ELSE, CASE - WHEN, WHILE- BREAK, GOTO, TRY - CATCH ,SQL SYSTEM FUNCTIONs)  (0) 2010.10.07
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유