0

I am trying to create a trigger that checks if the value after an update is 0 for a specific column. If the value is 0, the row should be deleted. I am not really familiar with triggers. I would apprecitate it if someone clould show/explain it to me. This is what I tried:

CREATE TRIGGER [dbo].[after_update] 
   ON [dbo].[tbl_LagerPos]
   AFTER UPDATE
AS 
BEGIN
    DELETE FROM tbl_LagerPos WHERE Bestand = 0;
END
GO

Here Bestand is the one that should be checked if 0. If yes, then the whole row should be deleted. I know that this is checking the entire table and is basically wrong. So I need it for that specific record only.

Tom el Safadi
  • 6,164
  • 5
  • 49
  • 102

1 Answers1

0

Do not use a trigger for this. Make a check on the client. You can also add a column constraint to the database:

alter table dbo.Table1 add Column1 int not null constraint CHK_Column1 check (Column1 > 0);