Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 2703

Numerical sequence generation for automatic key creation

0 votes

MySQL suddenly producing out of sequence autoinc numbers

InnoDB does not generate auto-inc values less than the highest value in the table. Even if you use ALTER TABLE to set the auto-increment to a lower value, it immediately resets to the max+1 value. But …
Bill Karwin's user avatar
1 vote

Preserve Autoincrement ID

You can advance the "highest" value for the table like this: ALTER TABLE user AUTO_INCREMENT=5000; After you do that, the id value generated for the next insert will be 5001 or greater. The auto-incr …
Bill Karwin's user avatar
21 votes
Accepted

How are auto_increment keys handled in INSERT (SELECT * FROM...)

You can insert into an auto-increment column and specify a value. This is fine; it simply overrides the auto-increment generator. If you try to insert a value of NULL or 0 or DEFAULT, or if you omit …
Bill Karwin's user avatar
3 votes
Accepted

Export and import a table without a specific column

Another solution is to use LOAD DATA [LOCAL] INFILE, but override the columns list so the auto-increment value is inserted into a dummy variable: Here's a demo: I have a text file I call c.csv: 1 …
Bill Karwin's user avatar
1 vote

Is a unique index required for a sequential (autoincrementing) id?

Short answer: in InnoDB, the auto-increment column must be the leftmost column of some index, either the primary key (clustered) index, or else some secondary index. It doesn't have to be a unique key …
Bill Karwin's user avatar