How to automatically create a log when an exception is being received into SQL Server?



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

Post New Answer

More SQL Server Interview Questions

How to generate create function script on an existing function?

1 Answers  


What is transaction server implicit?

1 Answers  


How to use the inserted and deleted pseudo tables?

1 Answers  


What is 3nf normalization?

1 Answers  


How do I start and stop sql server?

1 Answers  


What is normalization and what are the different forms of normalizations?

2 Answers  


How do I partition a table in sql server?

1 Answers  


What is the difference between SQL notification and SQL invalidation?

1 Answers   MindCracker,


what is meant by sql injection with example and one more question how to catch the errors in sqlserver

2 Answers  


Explain the dbcc pintable command when would you use it?

1 Answers  


How to create a view on an existing table in ms sql server?

1 Answers  


Simple example for difference between select and cursor in sql

1 Answers  


Categories