Skip to content

Instantly share code, notes, and snippets.

@3F
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3F/e0584698d8ed12a45912 to your computer and use it in GitHub Desktop.
Save 3F/e0584698d8ed12a45912 to your computer and use it in GitHub Desktop.
-- example for http://stackoverflow.com/questions/24580287/#comment38085601_24580344
-- MySQL AI-generator & LAST_INSERT_ID()
INSERT INTO `user` (`id`, `email`) VALUES (1, 'email1'); -- or your INSERT IGNORE INTO
INSERT INTO `user` (`id`, `email`) VALUES (2, 'email2');
SELECT LAST_INSERT_ID(); -- should be 0 /note: all records successfully inserted
/*
CREATE TABLE `user` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(150) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`) -- inconsiderable for sample with 0 ^
) ENGINE=InnoDB
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment