Problem with writing a trigger I want to write a trigger on one of the tables in my database so that no one can update the column listprice (the price) by more than 10 percent.

I'm totally confused. I can't write the trigger.

The column would be like this:


listprice
1000
2000
3000 


and the calculation would be listprice=listprice*1.1
As long as we don't have sample data, I built simple table with three columns.

Sample solution to achive your problem:

CREATE TABLE TenPercent (Id INT IDENTITY(1,1), Name VARCHAR(256), Listprice NUMERIC(10,2));
GO

INSERT INTO TenPercent (Name,Listprice)
SELECT * FROM (VALUES ('Name',100.00)) T(Name,Listprice);
GO

CREATE TRIGGER TenPercent_Guard ON TenPercent
FOR UPDATE
AS
BEGIN
IF (UPDATE(ListPrice) AND
    EXISTS (SELECT * FROM TenPercent tp
        JOIN DELETED d ON tp.Id=d.Id AND tp.Listprice&gt;d.Listprice*1.1))
    THROW 50000,'You can''t UPDATE Listprice more then 10 percent.',1;
END
GO

UPDATE TenPercent
SET Listprice=150;
GO

SELECT * FROM TenPercent;
GO

UPDATE TenPercent
SET Listprice=110;
GO

SELECT * FROM TenPercent;
GO


I used a JOIN in the trigger body to achive a situation when more then one row will be updated.

Obviously you should fit this solution to your table structure.