MulaiMulai sekarang secara gratis

CATCHING the RAISERROR

You need to select a product from the products table using a given product_id.

If the select statement doesn't find any product, you want to raise an error using the RAISERROR statement. You also need to catch possible errors in the execution.

Latihan ini adalah bagian dari kursus

Transactions and Error Handling in SQL Server

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

DECLARE @product_id INT = 5;

IF NOT EXISTS (SELECT * FROM products WHERE product_id = @product_id)
	-- Invoke RAISERROR with parameters
	___('No product with id %d.', ___, ___, ___);
ELSE 
	SELECT * FROM products WHERE product_id = @product_id;
Edit dan Jalankan Kode