isql (sql anywhere) trigger gives error

淺唱寂寞╮ 提交于 2019-12-12 01:52:40

问题


got strange error "Correlation name 'Club' not found" but the table Club is in the DB. I think the problem is after inserting the values:

ALTER TRIGGER "tg_add_club" AFTER INSERT,
UPDATE ON Club
REFERENCING NEW AS item
FOR EACH ROW
WHEN (item.address NOT IN (SELECT name FROM Place))
BEGIN 
 //DECLARE i_id INTEGER;
 INSERT INTO Place(name)
 VALUES (item.address);
 //SELECT @@identity INTO i_id;
 UPDATE Club SET place = (SELECT id FROM Place WHERE name=item.address)
 WHERE Name = item.name; //AND Place.name = item.address;
END

I think the problem is somewhere after VALUES (item.address), but I'm not sure.

Have tried different things with it, but still nothing works. Thanks for reading!


回答1:


The problem was, that the SET place and WHERE Name should be the same, or it would give me the error. Should work now:

UPDATE Club SET Name = (SELECT id FROM Place WHERE name=item.address) WHERE Name = item.name;

If it's new address, then the random id is made and Club gets the id from the table, where all the addresses are stored.



来源:https://stackoverflow.com/questions/8464454/isql-sql-anywhere-trigger-gives-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!