在mysql数据库中创建新的触发器

时间:2018-02-20 11:31:06

标签: mysql sql triggers

我在mysql数据库中有这个TRIGGER,但是我有错误 这是我的TRIGGER CODE

CREATE TRIGGER `chk_mac_after_insert` AFTER INSERT ON `radacct`
 FOR EACH ROW BEGIN
  # Check if user mac is already added in radcheck table,
 SET @mac = (SELECT count(*) from radcheck where username=New.username and 
 attribute='Calling-Station-ID');
# If there is no entry for mac, then update mac in radcheck table, so that 
in future only this mac will be able to connect with that username
IF (@mac = 0) THEN 
INSERT into radcheck (username,attribute,op,value) values 
(NEW.username,'Calling-Station-ID',':=',NEW.callingstationid); 
# add mac in users table for general record purpose
 UPDATE users SET mac = NEW.callingstationid where username = NEW.username;
  # trim mac for first 3 strings to detect vendor company
 SET @mactrim = (select LEFT(mac, 8) from users where 
 username=New.username);
# get vendor name from mac db table
SET @macvendor1 = (select vendor from macdb where oui=@mactrim);
# Update vendor name in user table
UPDATE users SET macvendor=@macvendor1 where username = NEW.username;
END IF;
END

但我有这个错误

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

0 个答案:

没有答案