SQL Server में Transactions और Error Handling
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
UNIQUE KEY constraint 'unique_name' का उल्लंघन.
'dbo.products' ऑब्जेक्ट में डुप्लिकेट key डाली नहीं जा सकती.
डुप्लिकेट key मान (Trek Powerfly 5 - 2018) है.
Error number

select * from sys.messages
| message_id | language_id | severity | ... | text |
|------------|-------------|----------|-----|-----------------------------------------------------------------|
| ... | ... | ... | ... | ... |
| 2627 | 1033 | 14 | ... | Violation of %ls constraint '%.*ls'. Cannot insert duplicate... |
| ... | ... | ... | ... | ... |
Severity level

State

Line

Procedure

Severity 11 से कम (11-19 पकड़ी जा सकती हैं)
Severity 20 या अधिक, जो कनेक्शन रोक दे
Compilation errors: जो ऑब्जेक्ट और कॉलम मौजूद नहीं हैं
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 में Transactions और Error Handling