zelig Posted March 30, 2012 Share Posted March 30, 2012 Is there a way to copy an auto-increment value (`id`) into another field in the same table (`org_id`)? So, when someone creates a new organization, it will copy the new auto-increment value into the org_id field. Is this possible? Thanks! Link to comment https://forums.phpfreaks.com/topic/259982-copy-an-auto-increment-value-to-another-field/ Share on other sites More sharing options...
chriscloyd Posted March 30, 2012 Share Posted March 30, 2012 create a mysql trigger http://dev.mysql.com/doc/refman/5.1/en/create-trigger.html delimiter | CREATE TRIGGER orgid BEFORE INSERT ON `table` FOR EACH ROW BEGIN UPDATE `table` SET org_id = NEW.id; END; | [/Code] Link to comment https://forums.phpfreaks.com/topic/259982-copy-an-auto-increment-value-to-another-field/#findComment-1332546 Share on other sites More sharing options...
btherl Posted March 30, 2012 Share Posted March 30, 2012 Will that trigger work being run "before insert"? Link to comment https://forums.phpfreaks.com/topic/259982-copy-an-auto-increment-value-to-another-field/#findComment-1332594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.