Database/SQL Server

SQL Server - 트랜잭션 (Transaction)

청렴결백한 만능 재주꾼 2020. 12. 9. 04:59
반응형

트랜잭션이란 ?

트랜잭션은 데이터베이스에 저장된 데이터의 변경 명령문의 집합이다. 트랜잭션은 단일 개념으로 취급되며 성공하던지 실패하던지 둘 중하나이다. 진행되다가 중간에 에러가 나거나 문제가 생기면 롤백이 된다. 이로써 데이터 베이스의 무결성을 유지한다.

 

What is a Transaction ?

A transaction is a group of commands that change the data stored in a database. A transaction, is treated as a single unit. A transaction ensures that, either all of the commands succeed, or none of them. If one of the commands in the transaction fails, all of the commands fail, and any data that was modified in the daabase is rolled back. In this way, transactions maintain the integrity of data in a database.

 

트랜잭션 진행 단계

1. 트랜잭션 시작

2. 데이터베이스 명령문 실행

3. 에러 체크 

4-1. 만약 에러가 났다면 롤백

4-2. 에러가 나지 않았다면 최종 처리

 

메모 : 커밋(최종 처리)되지 않은 변경은 없다.

Note : Not able to see the un-committed changes

 

example

 

트랜잭션 ACID 테스트 Transaction ACID Test

원자성 Atomic

모든 트랜잭션의 명령문은 시작되면 끝까지 가서 커밋이 되거나 다시 시작점으로 와야한다. 중간은 없어야 한다.

All statements in the transaction either completed successfully or they were all rolled back. The task that the set of operations represents is either accomplished or not, but in any case not left half-done.

 

일관성 Consistent

트랜잭션의 작업은 항상 논리적으로 일관성 있어야 한다. 

All data touched by the transaction is left in a logically consistent state.

 

독립성 Isolated

트랜잭션이 진행될 때 다른 트랜잭션이 진행 된다 하더라도 영향을 주지 않아야 한다. 이렇게 해야 트랜잭션이 커밋되지 않은 데이터를 변경할 수 없게 된다. 대부분의 데이터베이스는 잠금을 사용하여 독립성을 유지한다.

The transaction must affect data without interfering with other concurrent transactions, or being interfered with bty them. This prevents transactions from making changes to data based on uncommitted information, for example chancges to a record that are subsequently rolled back. Most Databases use locking to maintain transaction isolation.

 

지속성 Durable

한번 변경되어 커밋된 것은 영속성을 지닌다. 만약 정전이나 다른 문제가 셋 명령이 완료되기전에 생겼다면 데이터는 원래대로 돌아간다.

Once a change is made, it is permanent. If a system error or power failure occurs before a set of commands is complete, those commands are undone and the data is restored to its original state once the system begins running again.

반응형