我有一個帶有屬性值的表,eventid。我想讓觸發器代碼檢查一個特定的事件是否已經被插入了三次,如果是,拋出和異常每次都有一個相同的eventid值插入到表中。觸發重複屬性sql
我使用下面的代碼:
CREATE TRIGGER 'timeslotattendantcheck'
BEFORE INSERT ON 'attendants'
FOR EACH ROW
DECLARE @v_dup int;
BEGIN
SELECT @v_dup=COUNT(*) from attendants where attendant=:NEW.attendant;
if v_dup > 3 then
Raise_Application_Error (-20100, 'Too many attendants for one time slot. The insert is cancelled.');
end if;
end;
什麼是你的問題? – 2014-10-20 18:28:02
這裏有很多語法錯誤!請參閱下面的回答 – Barranka 2014-10-20 18:33:03
mysql服務器拋出一個異常「你的SQL語法有錯誤;查看與你的MySQL服務器版本相對應的手冊,以便在'Declare @vdup int DEFAULT 0; BEGIN SELECT @v_dup附近使用正確的語法= count(*)from ... – gnas 2014-10-20 18:36:16