当输入 table Animal 时,如果标价是奇数,则将其加 1,然后将其插入 table

When an entry is made to table Animal , if the list price is an odd number then add 1 to it and then insert it into the table

CREATE TRIGGER CHANGEEVEN ON ANIMAL
AFTER INSERT 
AS
BEGIN
     IF LISTPRICE %2!=0
        SET LISTPRICE=LISTPRICE+1
    ELSE
        SET LISTPRICE=LISTPRICE;
END

你想要一个 instead of 触发器。对于 SQL 服务器,您的语法看起来非常错误。您指的不是 inserted.

它应该看起来像:

CREATE TRIGGER CHANGEEVEN ON ANIMAL
INSTEAD OF INSERT 
AS
BEGIN
    INSERT INTO ANIMAL (LISTPRICE, . . . )  -- list columns here
        SELECT (CASE WHEN LISTPRICE % 2 = 1 THEN LISTPRICE + 1
                     ELSE LISTPRICE
                END),
               . . .   -- rest of columns here
        FROM inserted i;
END;