我有一张名为Card的桌子:
Card:
id (char(10))
points (int)
activated (bool)
activationDate(DateTime)
默认情况下,activate设置为false。我想要做的是在更新卡片激活后第一次设置activationDate设置为true。
答案 0 :(得分:1)
可能是这样的
create trigger TriggerName
on Card
for update as
if update(activated )
begin
if exists (select activated from card
where activated= false && ID =SomeValue)
begin
rollback trigger with
raiserror 24004 "Update failed "
end
else
begin
update Card
set activationDate= GETDATE() Where ID=someValue
end
end