ALTER TABLE monitoring_ternak
ADD COLUMN ternak_id INT NOT NULL AFTER id;

UPDATE monitoring_ternak
INNER JOIN master_ternak ON monitoring_ternak.eartag = master_ternak.eartag
SET monitoring_ternak.ternak_id = master_ternak.id
WHERE monitoring_ternak.eartag = master_ternak.eartag;

ALTER TABLE monitoring_ternak DROP eartag;