Test Trigger Code Sql Server Use Myguitarshop Drop Trigger Exists Productsupdate Go Create Q37196863

How do I test this Trigger code for SQL SERVER?

Use MyguitarShop;

DROP TRIGGER IF EXISTS Products_UPDATE;

GO

— Create the trigger

CREATE TRIGGER Products_UPDATE

— Fire trigger by updating the discount percent to 25% forproductID 1 by typing the percent as .25 instead of 25.

ON Products

INSTEAD OF UPDATE

AS

  

BEGIN

DECLARE @DiscountPercent money;

SET @DiscountPercent = (SELECT DiscountPercent FROMProducts);

–IF @DiscountPercent > 0 OR @DiscountPercent <= 1

IF @DiscountPercent BETWEEN 0 and 1

SET @DiscountPercent = @DiscountPercent * 100;

IF @DiscountPercent > 100 OR @DiscountPercent < 0

PRINT ‘ERROR Precentage Should be between 0-100’;

END;

TABLE PRODUCTS:

DiscountPercent(money, not null)


Answer


You could run a trace via Profiler to test if the trigger isfired, or you could

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.