为什么触发器没有向表中插入新值?

时间:2017-08-25 22:54:43

标签: sql sql-server

我有这个触发器来检查insert语句的条件。它显示正确的消息,但它不会添加值(尽管它显示msg“已成功添加”)。有谁知道问题是什么?

configureRouter(config, route) {
   ...
   config.options.pushState = true;
   ...
}

例如,当我跑:

CREATE TRIGGER trg_SentMessage_Insteadof
ON messages
INSTEAD OF INSERT
AS 
BEGIN
    IF (EXISTS (SELECT inserted.*
                FROM inserted 
                LEFT OUTER JOIN matchs AS m ON (inserted.sentFrom = m.userID1 
                                                AND inserted.sentTo = m.userID2)
                                            OR (inserted.sentFrom = m.userID2 
                                                AND inserted.sentTo = m.userID1)
                WHERE (m.interesting1 = 0 AND m.interesting2 = 0)))
         PRINT 'Succesfully added' 
    ELSE
    BEGIN
        ROLLBACK TRANSACTION
        PRINT 'You can't do that!'  
    END
END 

应该返回“Successfully added”,并将其添加到表中,但它只显示消息。

1 个答案:

答案 0 :(得分:1)

您实际上并未插入任何值。 public class ConcreteClass : BaseClass<ListClass> { public override List<ListClass> History { get; set; } } public abstract class BaseClass<T> where T : BaseListClass { public abstract List<T> History { get; set; } } public abstract class BaseListClass { } public class ListClass : BaseListClass { } 可防止插入发生,因此您必须在检查条件后在print语句之前自行插入它们。 就像是 https://stackoverflow.com/a/27659693/6715484