0
我有一個MYSQL表和兩個字段被稱爲Rate_per_unit和成本。首先,我希望Rate_per_unit字段從另一個名爲SHD_TEACHER的表中填充,然後我希望字段COST根據SHD_TEACHER中的RATE填充並乘以UNITS。MYSQL多個觸發器
我有以下的代碼是給我的錯誤:
CREATE TRIGGER RATE_PER_UNIT_1
BEFORE INSERT ON SHD_SCHEDULE
FOR EACH ROW
SET NEW.RATE_PER_UNIT =
(
SELECT RATE
FROM SHD_TEACHER
WHERE TEACHERID = NEW.TEACHER_ID
LIMIT 1
)
SET NEW.COST = (
SELECT RATE
FROM SHD_TEACHER
WHERE TEACHERID = NEW.TEACHER_ID
) * UNITS
任何幫助嗎?使用你的語法
感謝
許多感謝,但在這兩個你的例子,我得到一個錯誤:「您的SQL語法錯誤;」 – elstiv
好了,感謝@Gordon Linoff。下面是代碼:DELIMITER $$ CREATE TRIGGER RATE_PER_UNIT_2 BEFORE INSERT ON SHD_SCHEDULE FOR EACH ROW BEGIN SET = NEW.RATE_PER_UNIT ( SELECT RATE FROM SHD_TEACHER噸 WHERE t.TEACHERID = NEW.TEACHER_ID LIMIT 1 ); SET NEW.COST = ( SELECT t.RATE FROM SHD_TEACHER噸 WHERE t.TEACHERID = NEW.TEACHER_ID )* NEW.UNITS ; 結束 – elstiv