Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 1
    Probably want that trigger to run AFTER insert rather than BEFORE as the userid field doesn't have a value until after the insert is done. Commented Jan 22, 2009 at 16:44
  • 1
    try this: <code>CREATE TRIGGER default_assignment_self BEFORE INSERT ON users FOR EACH ROW BEGIN SET NEW.default_assignment = (SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='users'); END//</code> Commented Nov 7, 2011 at 22:57
  • This is real mess... the best solution for me was to update the userid with the value of the primary key immediately after insert. Commented Dec 15, 2020 at 8:16