日期:2014-05-16  浏览次数:20661 次

关于mysql触发器的问题,急等!!!
现在有一个building表,里边有三个字段,building_id,building_name,building_name.
Field Type Collation Null Key Default  
--------------- ----------- --------------- ------ ------ -------  
building_id int(11) (NULL) NO UNI (NULL)  
building_number int(11) (NULL) NO PRI (NULL)  
building_name varchar(32) utf8_general_ci NO PRI (NULL)  


还有另外一个表sql-write,里边有三个字段id(自增的),operation(varchar型),time(时间戳)
Field Type Collation Null Key Default Extra  
--------- ------------ --------------- ------ ------ ------- --------------  
id int(11) (NULL) NO PRI (NULL) auto_increment  
operation varchar(100) utf8_general_ci YES (NULL)  
time timestamp (NULL) YES (NULL)  
现在我的目的是:
1.在sql-write表上创建触发器
2.当building表中有记录删除时,把相应的sql语句写入sql-write中,我的sql代码如下  
SQL code

DELIMITER $$

CREATE
    TRIGGER `testtrigger`.`delete_building` AFTER DELETE
    ON `testtrigger`.`sql-write`
    FOR EACH ROW BEGIN
    declare @building_id,
    set @building_id=OLD.building_id;
     insert into sql-write set operation='delete from building where building_id=' old.building_id and time=now();
    END$$

DELIMITER ;

 
注:building表中building_id是主键,所以写入sql-write中的sql语句where后边的条件是building_id=old.building_id的

我感觉思路是对的,就是不知道语法哪里错了?


------解决方案--------------------
你要达到什么目的?看不懂你的SQL语句
------解决方案--------------------
insert into `sql-write` set