adspace


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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different types of subquery?

1235


Why we use the openxml clause?

1079


What kind of problems occurs if we do not implement proper locking strategy?

1499


How do I start sql server 2017?

1015


List the ways in which dynamic sql can be executed?

1086


If you're given a raw data table, how would perform etl (extract, transform, load) with sql to obtain the data in a desired format?

1047


What is acid mean in sql server?

1245


What are the kinds of subquery?

1107


What are wait types?

1249


What is normalization and what are the advantages of it?

1055


This question asked during interview, 2) At the end of each month, a new table is created for each bank that contains monthly metrics consolidated at the account level. The table naming convention is bankX_YYYYMM where X represents the numeric designation of the bank and YYYYMM indicates the 4 digit year and 2 digit month. The tables contain the following fields: name data type description account text account number registered boolean indicates whether the account is registered num_trans integer number of transactions made during the time period spend numeric(9,2) total spend during the time period a) Write a SQL query that will display the total number of transactions and total spend for "Bank1" during the 4th quarter of 2009. b) Write a SQL query that will display the total number of transactions and total spend at "Bank1" and "Bank2", broken out by registered vs. non-registered accounts, during January 2010 not sure what is correct answer and how to solve?

2567


What are the risks of storing a hibernate-managed object in a cache? How do you overcome the problems?

1197


Can we shrink data file in sql server?

1128


Can sql servers link to other servers like oracle?

916


How can you append an identity column to a temporary table?

1070