May 2020
Beginner
564 pages
14h 9m
English
SQL Server does error handling with the TRY and CATCH statements. The syntax for this is shown in the following code:
BEGIN TRY --sql statements END TRY BEGIN CATCH --sql statements END CATCHAnything you want to execute goes in the TRY statement, and if there is an error, the CATCH statement will run. If there is no error, the TRY statements are successfully executed, and the CATCH statement is never used.
The following query will try to insert values into the allstarfull table using the TRY and CATCH statements:
DECLARE @inplayerid varchar(9) = 'aaronha01';DECLARE @inyearid smallint = 1958; DECLARE @ingamenum smallint = 0;BEGIN TRY INSERT INTO allstarfull (playerid, yearid, gamenum) VALUES (@inplayerid, ...
Read now
Unlock full access