谁能告诉我为什么我的 table 字段引用不适用于此触发器查询?
Can anyone tell me why my table field reference not work with this trigger query?
我在为我的 sqlite 项目格式化更新触发器时遇到问题。
该项目有 2 tables。一个 table 叫做 Equipment
并且有 3 个字段:
- UnitID
- Last_PMI
- Preset_Hrs
另一个 table 称为 ESPModules
,它也有 3 个字段:
- UnitID (FK)
- ESPModuleID
- Install_Date
我在 ESPModules
table 上设置了一个更新触发器,每次我更改 ESPModules
table 中的 UnitID
字段时都会触发。 UnitID
字段与设备 table 具有一对一的关系。 (两个 table 只允许一个唯一的 UnitID
)
我的触发器实际上触发了,但我不知道如何在我的 ESPModules
table 中引用 UnitID
字段。下面是我到目前为止的内容,这段代码在触发时确实会更新设备记录:
UPDATE Equipment
SET Last_PMI = date('now'),
Preset_Hrs = 0
WHERE UnitID = "BT-109F"
UPDATE Equipment
SET Last_PMI = date('now'),
Preset_Hrs = 0
WHERE UnitID = ESPModules.UnitID;
但问题是我需要像上面那样引用我的 ESPModules.UnitID
字段:(换句话说,例如,当我输入一个现有的 UnitID
时,例如 "BT-109F",它确实会触发,但当我尝试引用我正在更新和保存的字段时不起作用。它会抛出此错误:“提交数据时发生错误:没有这样的列:ESPModules.UnitID
我是 sql 语言的新手,希望能帮助我正确格式化此更新查询。
谢谢
氏族
这在the SQLite create trigger
documentation中有解释:
the trigger actions may access elements of the row being inserted, deleted or updated using references of the form "NEW.column-name" and "OLD.column-name", where column-name is the name of a column from the table that the trigger is associated with.
所以,考虑一下:
UPDATE Equipment
SET Last_PMI = date('now'),
Preset_Hrs = 0
WHERE UnitID = NEW.UnitID;
我在为我的 sqlite 项目格式化更新触发器时遇到问题。
该项目有 2 tables。一个 table 叫做 Equipment
并且有 3 个字段:
- UnitID
- Last_PMI
- Preset_Hrs
另一个 table 称为 ESPModules
,它也有 3 个字段:
- UnitID (FK)
- ESPModuleID
- Install_Date
我在 ESPModules
table 上设置了一个更新触发器,每次我更改 ESPModules
table 中的 UnitID
字段时都会触发。 UnitID
字段与设备 table 具有一对一的关系。 (两个 table 只允许一个唯一的 UnitID
)
我的触发器实际上触发了,但我不知道如何在我的 ESPModules
table 中引用 UnitID
字段。下面是我到目前为止的内容,这段代码在触发时确实会更新设备记录:
UPDATE Equipment
SET Last_PMI = date('now'),
Preset_Hrs = 0
WHERE UnitID = "BT-109F"
UPDATE Equipment
SET Last_PMI = date('now'),
Preset_Hrs = 0
WHERE UnitID = ESPModules.UnitID;
但问题是我需要像上面那样引用我的 ESPModules.UnitID
字段:(换句话说,例如,当我输入一个现有的 UnitID
时,例如 "BT-109F",它确实会触发,但当我尝试引用我正在更新和保存的字段时不起作用。它会抛出此错误:“提交数据时发生错误:没有这样的列:ESPModules.UnitID
我是 sql 语言的新手,希望能帮助我正确格式化此更新查询。
谢谢
氏族
这在the SQLite create trigger
documentation中有解释:
the trigger actions may access elements of the row being inserted, deleted or updated using references of the form "NEW.column-name" and "OLD.column-name", where column-name is the name of a column from the table that the trigger is associated with.
所以,考虑一下:
UPDATE Equipment
SET Last_PMI = date('now'),
Preset_Hrs = 0
WHERE UnitID = NEW.UnitID;