Hiển thị kết quả từ 1 đến 3 / 3
  1. #1
    Tham gia
    26-10-2007
    Bài viết
    133
    Like
    0
    Thanked 1 Time in 1 Post

    [MYSQL] cần giúp vấn đề với Trigger

    mình có trigger như sau :
    Code:
    DELIMITER //
    DROP TRIGGER IF EXISTS update_type_tour
    CREATE TRIGGER update_type_tour
    AFTER  UPDATE ON ct_tour_type
    FOR EACH ROW
    BEGIN 
    DECLARE temp varchar(4),  temp_new varchar(100); 
              IF OLD.description != NEW.description THEN 
                       SET temp = OLD.description, temp_new = NEW.description;
              END IF;
              IF OLD.tour_type_code != NEW.tour_type_code THEN
                       SET temp = OLD.tour_type_code, temp_new = NEW.tour_type_code;
              END IF;
              IF OLD.description != NEW.description AND  OLD.tour_type_code != NEW.tour_type_code THEN  
                       SET temp = CONCAT(OLD.tour_type_code, ' và ', OLD.description), temp_new = CONCAT(NEW.tour_type_code, ' và ', NEW.description);
              END IF;
              INSERT INTO ct_log (done_by, done_work, done_date, action_flag)                  VALUES(NEW.last_aceessed_by, CONCAT('Cập nhật ', temp, ' thành ', temp_new), NOW(), 'update'); 
    
    END //
    DELIMITER ;
    mình chạy dc cái lệnh này thì successful nhưng sao khi update trên bảng ct_tour_type mà nó không insert được vào bảng ct_log nhỉ? mới tập tành viết trgger mong mn giúp

    vừa thử lại mà nó báo #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 'CREATE TRIGGER update_type_tour AFTER UPDATE ON ct_tour_type FOR EACH ROW BE' at line 2

    chả hiểu nổi :-?
    Mình xin cảm ơn trước !
    Được sửa bởi 1cnb07 lúc 23:31 ngày 19-07-2011
    Quote Quote

  2. #2
    Tham gia
    26-10-2007
    Bài viết
    133
    Like
    0
    Thanked 1 Time in 1 Post
    phù ! đã mò dc lỗi
    Code:
    delimiter $$
    DROP TRIGGER IF EXISTS update_type_tour $$
    # MySQL returned an empty result set (i.e. zero rows).
    
    # MySQL returned an empty result set (i.e. zero rows).
    
    CREATE TRIGGER update_type_tour
    BEFORE  UPDATE ON ct_tour_type
    FOR EACH ROW
    BEGIN 
    DECLARE temp varchar(120);
    DECLARE  temp_new varchar(120); 
              IF OLD.description != NEW.description THEN 
                       SET temp = OLD.description, temp_new = NEW.description;
              END IF;
              IF OLD.tour_type_code != NEW.tour_type_code THEN
                       SET temp = OLD.tour_type_code, temp_new = NEW.tour_type_code;
              END IF;
              IF OLD.description != NEW.description AND  OLD.tour_type_code != NEW.tour_type_code THEN  
                       SET temp = CONCAT(OLD.tour_type_code, ' và ', OLD.description), temp_new = CONCAT(NEW.tour_type_code, ' và ', NEW.description);
              END IF;
              INSERT INTO ct_log (done_by, done_work, done_date, action_flag)                  VALUES(NEW.last_accessed_by, CONCAT('Cập nhật ', temp, ' thành ', temp_new), NOW(), 'update'); 
    
    END $$
    
    delimiter ;

  3. #3
    Tham gia
    10-03-2009
    Location
    TP HCM
    Bài viết
    15
    Like
    1
    Thanked 0 Times in 0 Posts
    thanks bạn nha mình đang cần. Hjhj

Bookmarks

Quy định

  • Bạn không thể tạo chủ đề mới
  • Bạn không thể trả lời bài viết
  • Bạn không thể gửi file đính kèm
  • Bạn không thể sửa bài viết của mình
  •