Skip to Content
MySQL Reference Manual
book

MySQL Reference Manual

by Michael Widenius, David Axmark, Kaj Arno
June 2002
Intermediate to advanced
816 pages
20h 46m
English
O'Reilly Media, Inc.
Content preview from MySQL Reference Manual

Table Definition-Related Issues

Problems with ALTER TABLE

ALTER TABLE changes a table to the current character set. If get a duplicate key error during ALTER TABLE, the cause is either that the new character sets map to keys to the same value or that the table is corrupted, in which case you should run REPAIR TABLE on the table.

If ALTER TABLE dies with an error like this:

Error on rename of './database/name.frm' to './database/B-a.frm' (Errcode: 17)

the problem may be that MySQL has crashed in a previous ALTER TABLE and there is an old table named A-something or B-something lying around. In this case, go to the MySQL data directory and delete all files that have names starting with A- or B-. (You may want to move them elsewhere instead of deleting them.)

ALTER TABLE works the following way:

  • Create a new table named A-xxx with the requested changes.

  • All rows from the old table are copied to A-xxx.

  • The old table is renamed B-xxx.

  • A-xxx is renamed to your old table name.

  • B-xxx is deleted.

If something goes wrong with the renaming operation, MySQL tries to undo the changes. If something goes seriously wrong (this shouldn’t happen, of course), MySQL may leave the old table as B-xxx, but a simple rename on the system level should get your data back.

How to Change the Order of Columns in a Table

The whole point of SQL is to abstract the application from the data storage format. You should always specify the order in which you wish to retrieve your data. For example:

SELECT col_name1, col_name2, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

MySQL Troubleshooting

MySQL Troubleshooting

Sveta Smirnova
MySQL Cookbook

MySQL Cookbook

Paul DuBois
The MySQL Workshop

The MySQL Workshop

Thomas Pettit, Scott Cosentino, Dr. Vlad Sebastian Ionescu

Publisher Resources

ISBN: 0596002653Purchase bookErrata Page