MS-SQL문 강좌 12장
--트랜잭션 (시스템 트랜잭션, 사용자 트랜잭션)
set implicit_transactions on -- 쿼리 확인 명령을 기다려줌 rollback 가능
dbcc useroptions -- 현재 설정된 모드를 확인
--시스템 트랜잭션(시스템이 알아서 아래 예문과 같이 begin tran을 붙여준다)
-- 정전등의 상태에 대해 현 작업이 다시 rollback등이 되도록 만들어주기 위함
begin tran
update sales set qty = qty * 0.8 where title_id='bu1032'
commit
begin tran
update sales set qty = qty * 1.1 where title_id='tc3218'
commit
-- 사용자 트랜잭션(사용자가 임의로 트랜을 작성한다)
-- 사용자 트랜잭션 후 commit를 잊지 않는다(블록킹 일어남)
begin tran
update sales set qty = qty * 0.8 where title_id='bu1032'
update sales set qty = qty * 1.1 where title_id='tc3218'
commit
select * from titles
select @@trancount -- begin tran은 1증가 commit는 1감소(트랜젝션이 열려있는지 확인)
dbcc opentran -- 위와 같이 열려이는 트랜젝션 확인
begin tran
update titles set price=0
commit
rollback -- 무조건 처음까지 롤백(현재작업 모두최소)
begin Tran
begin tran
save tran myTran -- 변수 지정(save tran은 trancount를 증가시키지 않음)
rollback myTran -- 바로 윗줄까지만 rollback(지정해준 변수 이름까지 롤백)
commit
commit
sp_lock -- 디비 락 정보 표시
select db_name(5) -- 해당 디비 락 정보 표시
select object_name(85575343) -- 해당하는 디비에 가서 실행
select @@spid -- 현재 사용디비 spid 보여줌
0: table (heap)
1: table CL
2:...
sp_who -- 현재 시퀀스에 로그인한사람 목록 출력