【问题标题】:update a table after update in mssql triggers在 mssql 触发器中更新后更新表
【发布时间】:2014-07-29 12:46:50
【问题描述】:

我有两个表:productType 和 product 表。两个表都有一个属性“状态”。我想要发生的是,每当我更新 productType 状态时,产品的状态也会更新。我想为此使用触发器,但我不知道正确的语法。我正在使用 sql server management studio 2012。谢谢:)

【问题讨论】:

标签: sql-server database triggers


【解决方案1】:

在问题中提供更多信息,我可以给出更好的答案,但这应该可以帮助您入门:

CREATE TRIGGER trg1 
ON producttype 
after UPDATE 
AS 
    UPDATE product 
    SET    status = inserted.status 
    WHERE  rowid = inserted.rowid 

祝你好运!

【讨论】:

  • 您可能想要包含 where 子句或连接。您对此进行编码的方式将更新整个产品表。
猜你喜欢
  • 2021-03-27
  • 1970-01-01
  • 1970-01-01
  • 2011-05-31
  • 2016-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多