![]() |
|
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A.7.1 Problems with ALTER TABLE . | ||
A.7.2 How To Change the Order of Columns in a Table | ||
A.7.3 TEMPORARY TABLE problems |
ALTER TABLE
. ALTER TABLE
changes a table to the current character set.
If you get a duplicate key error during ALTER TABLE
, then the cause
is either that the new character sets maps two 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:
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.
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, col_name3 FROM tbl_name; |
will return columns in the order col_name1
, col_name2
, col_name3
, whereas:
SELECT col_name1, col_name3, col_name2 FROM tbl_name; |
will return columns in the order col_name1
, col_name3
, col_name2
.
If you want to change the order of columns anyway, you can do it as follows:
INSERT INTO new_table SELECT fields-in-new_table-order FROM old_table
.
old_table
.
ALTER TABLE new_table RENAME old_table
.
You should never, in an application, use SELECT *
and
retrieve the columns based on their position, because the order and
position in which columns are returned cannot may not remain
the same (if you add/move/delete columns). A simple change to your
database structure would then cause your application to fail.
Of course SELECT *
is quite suitable for testing queries.
The following are a list of the limitations with TEMPORARY TABLES
.
HEAP
, ISAM
,
MyISAM
, MERGE
, or InnoDB
.
mysql> SELECT * FROM temporary_table, temporary_table AS t2; |
RENAME
on a TEMPORARY
table.
Note that ALTER TABLE org_name RENAME new_name
works!
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
Hosting by: Hurra Communications Ltd.
Generated: 2007-01-26 17:58:44