Skip to content

Instantly share code, notes, and snippets.

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 CMCDragonkai/8e5ba2394fb0e31971ca2784d969e843 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/8e5ba2394fb0e31971ca2784d969e843 to your computer and use it in GitHub Desktop.
Import Rows with Auto-Increment ID Used on Multiple Fields #sql #mysql
LOCK TABLES test WRITE;
SET @next_id = (
SELECT AUTO_INCREMENT
FROM information_schema.TABLES
WHERE TABLE_SCHEMA=DATABASE() AND
TABLE_NAME='test'
);
INSERT INTO test
(id1, id2, id3)
VALUES
(@next_id, @next_id, @next_id),
(@next_id + 1, @next_id + 1, @next_id + 1);
SET @next_id = NULL;
UNLOCK TABLES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment