MSSQL의 트랜잭션이 테이블을 잠글 것인가? 그렇다면 잠금은 전체 트랜잭션 기간 동안 유지되거나 명령문 실행 기간 동안 만 보유됩니다. 다음은 트랜잭션의 예는 (구문 오류를 무시) MSSQL의 트랜잭션이 테이블을 잠글습니까
if (sqlsrv_begin_transaction($dbConnection) === false) {
die(print_r(sqlsrv_errors(), true));
}
$query = "INSERT INTO order_table (name,description,created_at) VALUES ('test_name','test_Transaction','some_date')";
$stmt1 = sqlsrv_query($dbConnection ,$query) or die('MSSQL error: ' . mssql_get_last_message());
$query = "INSERT INTO other_details_table (order_id,details) VALUES ('1234','order_details')";
$stmt2 = sqlsrv_query($dbConnection ,$query) or die('MSSQL error: ' . mssql_get_last_message());
sleep('20'); // used to delay the transaction time
/* If both queries were successful, commit the transaction. */
/* Otherwise, rollback the transaction. */
if($stmt1 && $stmt2) {
sqlsrv_commit($conn);
echo "Transaction committed.<br />";
} else {
sqlsrv_rollback($conn);
echo "Transaction rolled back.<br />";
}
위의 트랜잭션이 진행되는
, 나는 성공적으로 삽입, 테이블 'order_table'에 레코드를 삽입하려고합니다. 트랜잭션에있는 테이블을 잠그고 커밋 또는 롤백 한 후에 테이블의 잠금을 해제하려면 어떻게합니까?
트랜잭션은 트랜잭션이 커밋 될 때까지 다른 사용자로부터 관련 새 레코드를 숨 깁니다. 자고있는 동안 그 테이블에서 셀렉트를하는 사람은 새 데이터를 보지 못합니다. –
중복으로 보입니다. http://stackoverflow.com/questions/9842253/lock-table-while-inserting – FLICKER