Objective: Practice handling errors in your transactions using SQL Server.
Your task is to add error handling around the INSERT statement shown below. After the INSERT executes, your code must check for failure and, if needed, roll back the transaction and stop execution.
Use modern SQL Server error handling. In particular:
TRY...CATCH
CATCH
ERROR_MESSAGE()
THROW
Start from this base transaction:
BEGIN TRAN; INSERT INTO Clients (CompanyName, AddressLine1, City, State, Zip, ContactLastName, ContactFirstName, ContactPhone) VALUES ('Acme Limited', '400 Main Street', 'Chicago', 'IL', '60609', 'Jones', 'John', '1234567890'); COMMIT TRAN;
XACT_STATE()
Type or paste your finished T-SQL into the box below, then click Submit to view the results page. Do not include any solution output beyond what your script returns (for example, a final SELECT of an error message is acceptable).
SELECT