我正在编写酒店管理数据库的代码,用于学校分配。 我需要在触发器中插入一个查询,我的sql server给了我这个sintaxerror:
#1064查询SQL附近' SELECT codiceFiscale FROM IMPIEGATO WHERE ambiente = new.ambiente SET NEW.nome = U'第5行
CODE:
CREATE TRIGGER IF NOT EXISTS Gestione.ControlloExtra
BEFORE INSERT ON SPESEEXTRA
FOR EACH ROW
BEGIN
IF EXISTS SELECT codiceFiscale FROM IMPIEGATO WHERE ambiente=new.ambiente
SET NEW.nome=UPPER(NEW.nome);
答案 0 :(得分:2)
子查询需要括号:
CREATE TRIGGER IF NOT EXISTS Gestione.ControlloExtra
BEFORE INSERT ON SPESEEXTRA
FOR EACH ROW
BEGIN
IF EXISTS (SELECT i.codiceFiscale FROM IMPIEGATO i WHERE i.ambiente = new.ambiente)
SET NEW.nome = UPPER(NEW.nome);
END IF;
. . .
END;