I have got 2 tables named: train_information and axle.
Train_information
has the folowing:
train_id (PK)
train_name
train_length
number_of_axles
axle
has the folowing:
axle_id (PK)
train_id(FK)
axle
When I insert something on train_information and let's say for example put the number 16 in number_of_axles. I want the table axle to get that same information automatically.
How do i do this with a trigger?
EDIT:
it works now with this code:
CREATE TRIGGER TriggerName AFTER INSERT ON train_information
FOR EACH
ROW
BEGIN
INSERT INTO axle( train_id, axle )
VALUES (
NEW.train_id, NEW.number_of_axles
);
END
But right now, it enters for example the number 16 in the table axle but i want it to go like:
axle_id = 1
train_id = 1
axle = 1
axle_id = 2
train_id = 1
axle = 2
axle_id = 3
train_id = 1
axle = 3
Is this posible?