2016-04-08 35 views
0

sonra tetiği çağrılırken bir tablodan güncellenen satır nasıl Bu benim bir satır bugüncelleme

UPDATE product_table SET product_description ="product seven" WHERE product_number=9; 
gibi tablodan 9 ürün numarasını söylemek güncellemek demek istiyorum benim tablo yapısı

mysql> select * from product_table; 
+----------------+---------------------+ 
| product_number | product_description | 
+----------------+---------------------+ 
|    1 | product one   | 
|    2 | product two   | 
|    3 | product three  | 
|    9 | product five  | 
|    10 | product six   | 
|    11 | product six   | 
+----------------+---------------------+ 

olduğunu

Yani tetikleyici i böyle tetiği yazdım ve herhangi hatasız oluşturulduğunu var

product_table tablodan gelen güncellenmiş ürün numarasını alabilirsiniz. Sonra

DELIMITER // 
CREATE TRIGGER product_table_update 
     AFTER UPDATE 
     ON product_table 
     FOR EACH ROW 
BEGIN 


     DECLARE l_product_number INT; 
    set @l_table_name = 'product_table'; 
    set @l_action = 'updation'; 


       SET @l_table_column = 'product_description'; 
select new.product_number into @l_product_number from product_table;// here is i think where the problem is , i am trying to fetch the updated row to l_product_number 

     IF (OLD.product_description <> NEW.product_description) THEN 
     SET @oldval = OLD.product_description; 
     SET @newval = NEW.product_description; 
     select concat(@oldval,@newval) into @l_description; 

     END IF; 

     INSERT INTO audit_table_test 
     (table_name, 
     changed_row_id, 
     action, 
     table_column, 
     change_desciption, 
     change_time 
    ) 
     VALUES 
    (@l_table_name, 
     @l_product_number, 
     @l_action, 
     @l_table_column, 
     @l_description, 
    NOW() 
    ); 
END; // 
DELIMITER ; 

i Sorunun bu kodu

select new.product_number into @l_product_number from product_table;// here is i think where the problem is , i am trying to fetch the updated row to l_product_number 

olmak zorunda biliyorum bu hata

ERROR 1172 (42000): Result consisted of more than one row 

gösteren bu

UPDATE product_table SET product_description ="product seven" WHERE product_number=11; 

gibi güncellemek için çalıştı Lütfen birisi güncellemeyi almama yardım etsin Bu tetiği

cevap

1

deneyin çağırmayı sıra: Çok şimdi pek çok yerde bu mantığı uygulayabilirsiniz thaaanQ

... 
SET @l_table_column = 'product_description'; 

/* 
here is i think where the problem is , i am trying to fetch the 
updated row to l_product_number 
*/ 
-- select new.product_number into @l_product_number from product_table; 
SET @l_product_number := NEW.product_number; 

IF (OLD.product_description <> NEW.product_description) THEN 
... 
+0

u hayat koruyucu r !!!! – Mukund