Another approach, which I have found to be easier most of the time, is to:
- move your table to another table (possibly TEMPORARY) : CREATE
(TEMPORARY) TABLE tmp SELECT * FROM MyTable
- create MyTable again
- insert rows from other table (here: "tmp") : INSERT INTO MyTable
SELECT id AS id, oldField AS newField FROM tmp
It may be a little more expansive than ALTER, but it's definitely easier since:
- you don't need to analyse the original table at all to check for
- mapping from old table to new table is really easy (needed only if
column names don't match or old table had more columns than the new
On Mon, Sep 12, 2011 at 3:38 PM, Nicolas Cannasse
<[hidden email]> wrote:
> Le 12/09/2011 14:30, benjamin Dubois a écrit :
>> Since you can create a table, is there a way to alter a table (without
>> removing remaining column content) ?
> Yes, but you need to analyze the current table description (as returned by
> SHOW CREATE TABLE) then list the differences and build the requests to
> "sync" your database.
> We already have such a tool at MotionTwin but it's tied to our in-house
> framework so not releasable as-it.
> haXe - an open source web programming language
> http://haxe.org >