SQL Server에서의 트랜잭션과 오류 처리
Miriam Antona
Software Engineer
INSERT INTO products (product_name, stock, price)
VALUES ('Trek Powerfly 5 - 2018', 10, 3499.99);
Msg 2627, Level 14, State 1, Line 1
Violation of UNIQUE KEY constraint 'unique_name'.
Cannot insert duplicate key in object 'dbo.products'.
The duplicate key value is (Trek Powerfly 5 - 2018).
오류 번호

select * from sys.messages
| message_id | language_id | severity | ... | text |
|------------|-------------|----------|-----|-----------------------------------------------------------------|
| ... | ... | ... | ... | ... |
| 2627 | 1033 | 14 | ... | Violation of %ls constraint '%.*ls'. Cannot insert duplicate... |
| ... | ... | ... | ... | ... |
심각도 레벨

상태(State)

라인(Line)

프로시저

심각도 11 미만 (11–19는 포착 가능)
연결을 중단하는 심각도 20 이상
컴파일 오류: 존재하지 않는 개체와 열
BEGIN TRY
SELECT non_existent_column FROM products;
END TRY
BEGIN CATCH
SELECT 'You are in the CATCH block' AS message;
END CATCH
Msg 207, Level 16, State 1, Line 2
Invalid column name 'non_existent_column'.
SQL Server에서의 트랜잭션과 오류 처리