2016-04-07 15 views
0

Was mache ich falsch?Mysql TIMESTAMP-Trigger funktioniert nicht

Ich habe table1 auf INSERT Daten table1 Ich habe Trigger:

BEGIN 
    INSERT INTO table2 (`c_id`, `date`, `product_id`, `price`) 
    VALUES (
      NEW.c_id, 
      NEW.date = CURRENT_TIMESTAMP, 
      NEW.product_id, 
      NEW.price 
     ); END 


CREATE TABLE `table2` (
    `id` int(11) NOT NULL AUTO_INCREMENT, 
    `c_id` int(11) NOT NULL, 
    `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
    `product_id` int(11) NOT NULL, 
    `price` decimal(9,2) DEFAULT NULL, 
    PRIMARY KEY (`id`), 
    KEY `c_data` (`c_id`,`date`,`product_id`) 
) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=latin1; 

Als Ergebnis erhalte ich 0000-00-00 00.00.00 Datum

MySQL Version 5.6.28

+0

Entfernen Sie 'date' und NEW.date = CURRENT_TIMESTAMP aus der Abfrage einfügen. Standardmäßig wird mysql das Datum dafür setzen. –

+0

MySQL Version 5.6.28 –

+0

@MangeshSatheIND meinen Sie: BEGIN einfügen in competitor_pricing ('competitor_id',' variant_id', 'price') Werte (NEW.competitor_id, NEW.variant_id, NEW.price); ENDE ??? –

Antwort

0

Entfernen Sie date und NEW.date = CURRENT_TIMESTAMP, von einfügen Abfrage. Standardmäßig mysql wird date dafür gesetzt.

INSERT INTO table2 (`c_id`, `product_id`, `price`) 
    VALUES (
      NEW.c_id, 
      NEW.product_id, 
      NEW.price 
     );