How to automatically create a log when an exception is being received into SQL Server?
Answer / Chandra Shekher
To automatically create a log of exceptions in SQL Server, you can use TRY-CATCH blocks along with the RAISERROR statement. Here's a simple example:
```sql
BEGIN TRY
-- Your code here
END TRY
BEGIN CATCH
-- Insert error details into an error log table here
INSERT INTO ErrorLog (ErrorNumber, ErrorMessage) VALUES (ERROR_NUMBER(), ERROR_MESSAGE())
END CATCH
```
| Is This Answer Correct ? | 0 Yes | 0 No |
How to generate create function script on an existing function?
What is transaction server implicit?
How to use the inserted and deleted pseudo tables?
What is 3nf normalization?
How do I start and stop sql server?
What is normalization and what are the different forms of normalizations?
How do I partition a table in sql server?
What is the difference between SQL notification and SQL invalidation?
what is meant by sql injection with example and one more question how to catch the errors in sqlserver
Explain the dbcc pintable command when would you use it?
How to create a view on an existing table in ms sql server?
Simple example for difference between select and cursor in sql
Oracle (3253)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)