Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am having a table name link with two columns link1 and link2 and another table name hide with four columns hide1, link1,link2 and hide2. If i insert data into link table the data should insert into hide table in the column link1 and link2..

How can i write a query for this?

Here my query its not executing:

CREATE TRIGGER linkTRIGGER
    AFTER INSERT ON link
     FOR EACH ROW BEGIN 
       INSERT INTO Hide(link1,link2) VALUES(OLD.link1,OLD.link2)
share|improve this question
    
What should go to the other 2 columns of Hide? Can you add sample data? –  ypercube Jul 1 '13 at 11:18

1 Answer 1

First, Hide has 4 columns and you provide values for only 2 of them. What should go to the other 2?

Second as the Trigger syntax in MySQL documentation states:

In an INSERT trigger, only NEW.col_name can be used; there is no old row.

So, you can use NEW.link1, NEW.link2 but not OLD.link1, OLD.link2 and this would be valid:

CREATE TRIGGER linkTRIGGER
    AFTER INSERT ON link
     FOR EACH ROW BEGIN 
       INSERT INTO Hide (link1, link2, hide1, hide2) 
       VALUES (NEW.link1, NEW.link2, NEW.link1, NEW.link2) ;

but no idea if that's what you want. Depends what values you want to pass to the two hide columns.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.