Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

418


Part IV: Programming with T-SQL


SQL Server Log
SQL Server also maintains a series of log fi les. Each time SQL Server starts, it creates a new
log fi le. Six archived copies of the last log fi les are retained, for a total of seven log fi les.
Management Studio’s Object Explorer in the Management ➪ SQL Server Logs node lists the
logs. Double-clicking a log opens SQL Server’s cool Log File Viewer, as shown in Figure 16-2.
It’s worth exploring because it has a fi lter and search capabilities.

FIGURE 16-2
Viewing an error in the SQL Server log using Management Studio.

Tr y...Catch
TRY.. .CATCH is a standard method to trap and handle errors that .NET programmers have
enjoyed for years. The basic idea is that if SQL Server encounters any errors when it tries to
execute a block of code, it stops execution of the TRY block and immediately jumps to the
CATCH block to handle the error:

c16.indd 418c16.indd 418 7/30/2012 5:38:11 PM7/30/2012 5:38:11 PM


http://www.it-ebooks.info
Free download pdf