Say I have the following MyISAM table (example-ified) in a Windows-hosted DB:
CREATE TABLE foo ( column1 CHAR(1), column2 CHAR(1), UNIQUE KEY `keyX`(`column1`));
I have to perform an update of the key to extend it to both columns (it's an example,
ignore the content of the key), and want to ensure data integrity while I recreate it.
The following is what I thought I had to do:
LOCK TABLES foo WRITE;
DROP INDEX `keyX` ON `foo`;
CREATE UNIQUE INDEX `keyX` ON `foo` (`column1`,`column2`);
After much head-scratching due to "Error Code : 1100 Table 'foo' was not locked with LOCK
TABLES", I discovered that CREATE / DROP INDEX statements are mapped to equivalent ALTER
TABLE statements. This, due to the way ALTER TABLE statements 'work' on windows, renders
this code unusable as the DROP INDEX statement unlocks the table. Before the CREATE INDEX
statement will work I then have to run UNLOCK TABLES, which also makes sense (I thought it
So - I can't lock the table whiel I drop then recreate the index, so what's the best way
to do this?
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email