SlideShare a Scribd company logo
Presented by Aaron Buma
Error Messages – How to get them
 CREATE objects that already exist
 Violating Foreign Keys
 Exceeding permissions
 Trying operations that aren’t allowed (PRINT in a UDF)
Error Messages – Basic layout
 Message Number
 Number 50,000 for custom messages (default)
 State – You can track error locations with custom errors
 Severities
 1-10: Status Info (Not Bad)
 11-16: Can be corrected by the user (Fixable)
 17-19: Errors with SQL Resources (Bad)
 20-25: System Problems, Fatal Errors (Really Bad)
Error Messages - Custom
 You create message and severity
 Only users with SysAdmin role or Alter Trace can use
WITH LOG – writes to error log
 You can have parameters in the text
 You can use Profiler to watch for them
 Watch for message number ‘50,000’ or a specific State
Error Handling
 Statement Termination - skip statement, but continue
 Scope Abortion - Exit this object, but continue
 Batch Abortion - Stop calling object
 Connection Termination – Disconnect, rollback open Trans
 ~ Severity > 20
Error Handling - XACT_ABORT
 If ON and in a transaction, it will rollback transaction
 SET XACT_ABORT ON / OFF
 Errors with Severity 11-16 cause Batch Abortion
Error Handling - TRY and CATCH
 BEGIN TRY
 Have your statements in the TRY, including BEGIN TRANs
 BEGIN CATCH
 Run code when error encountered
 You have access to the error properties
Demo

More Related Content

PPTX
Exception handling in SQL with Execution
PDF
Handling errors in t sql code (1)
PPT
Error management
PPT
Oracle PL/SQL exception handling
DOCX
Exceptions in SQL Server
PPTX
Debugging
PPT
SQL Views
Exception handling in SQL with Execution
Handling errors in t sql code (1)
Error management
Oracle PL/SQL exception handling
Exceptions in SQL Server
Debugging
SQL Views

More from Aaron Buma (8)

PDF
SQL Triggers
PPT
SQL Server - Constraints
PPTX
SQL Server GUIDS (Globally Unique Identifiers)
PPTX
XQuery Extensions
PPT
Spatial data types
PPTX
Drone Building 101
PPTX
Set Operators, Derived Tables and CTEs
PPTX
Aggregating data
SQL Triggers
SQL Server - Constraints
SQL Server GUIDS (Globally Unique Identifiers)
XQuery Extensions
Spatial data types
Drone Building 101
Set Operators, Derived Tables and CTEs
Aggregating data
Ad

Recently uploaded (20)

PPTX
L1 - Introduction to python Backend.pptx
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
assetexplorer- product-overview - presentation
PDF
top salesforce developer skills in 2025.pdf
PPT
Introduction Database Management System for Course Database
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
ai tools demonstartion for schools and inter college
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
history of c programming in notes for students .pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
L1 - Introduction to python Backend.pptx
Understanding Forklifts - TECH EHS Solution
assetexplorer- product-overview - presentation
top salesforce developer skills in 2025.pdf
Introduction Database Management System for Course Database
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Upgrade and Innovation Strategies for SAP ERP Customers
ai tools demonstartion for schools and inter college
Digital Systems & Binary Numbers (comprehensive )
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
How to Migrate SBCGlobal Email to Yahoo Easily
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Computer Software and OS of computer science of grade 11.pptx
Design an Analysis of Algorithms I-SECS-1021-03
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
history of c programming in notes for students .pptx
Operating system designcfffgfgggggggvggggggggg
Ad

SQL: Error Messages and Error Handling

  • 2. Error Messages – How to get them  CREATE objects that already exist  Violating Foreign Keys  Exceeding permissions  Trying operations that aren’t allowed (PRINT in a UDF)
  • 3. Error Messages – Basic layout  Message Number  Number 50,000 for custom messages (default)  State – You can track error locations with custom errors  Severities  1-10: Status Info (Not Bad)  11-16: Can be corrected by the user (Fixable)  17-19: Errors with SQL Resources (Bad)  20-25: System Problems, Fatal Errors (Really Bad)
  • 4. Error Messages - Custom  You create message and severity  Only users with SysAdmin role or Alter Trace can use WITH LOG – writes to error log  You can have parameters in the text  You can use Profiler to watch for them  Watch for message number ‘50,000’ or a specific State
  • 5. Error Handling  Statement Termination - skip statement, but continue  Scope Abortion - Exit this object, but continue  Batch Abortion - Stop calling object  Connection Termination – Disconnect, rollback open Trans  ~ Severity > 20
  • 6. Error Handling - XACT_ABORT  If ON and in a transaction, it will rollback transaction  SET XACT_ABORT ON / OFF  Errors with Severity 11-16 cause Batch Abortion
  • 7. Error Handling - TRY and CATCH  BEGIN TRY  Have your statements in the TRY, including BEGIN TRANs  BEGIN CATCH  Run code when error encountered  You have access to the error properties