db-ddlutils-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Dudziak" <tom...@gmail.com>
Subject Re: Plataform.getAlterTablesSql results
Date Wed, 14 Jun 2006 14:02:58 GMT
On 6/14/06, Douglas Granzotto (Infoarte) <dgranzotto@infoarte.trix.net> wrote:

> I am using the following method:
> String getAlterTablesSql(Database desiredDb, boolean doDrops, boolean modifyColumns,
boolean continueOnError)
> from Plataform
>
> It is returning this sql code:
> ALTER TABLE IPI
>     ADD CLASSFISCAL VARCHAR(12);
>
> ALTER TABLE IPI
>     ALTER CLASSFISCAL POSITION 4;
>
> CREATE TABLE IPI_
> (
>     IPICOD VARCHAR(2) NOT NULL,
>     IPIDESC VARCHAR(30),
>     TIPO INTEGER,
>     CLASSFISCAL VARCHAR(12),
>     VERSAO INTEGER,
>     PRIMARY KEY (IPICOD)
> );
>
> INSERT INTO IPI_ (CLASSFISCAL,IPICOD,IPIDESC,TIPO,VERSAO) SELECT CLASSFISCAL,IPICOD,IPIDESC,TIPO,VERSAO
FROM IPI;
>
> DROP TABLE IPI;
>
> CREATE TABLE IPI
> (
>     IPICOD VARCHAR(2) NOT NULL,
>     IPIDESC VARCHAR(30),
>     TIPO INTEGER,
>     CLASSFISCAL VARCHAR(12),
>     VERSAO INTEGER,
>     PRIMARY KEY (IPICOD)
> );
>
> CREATE INDEX IX_IPI_1 ON IPI (IPIDESC);
>
> INSERT INTO IPI (IPICOD,IPIDESC,TIPO,CLASSFISCAL,VERSAO) SELECT IPICOD,IPIDESC,TIPO,CLASSFISCAL,VERSAO
FROM IPI_;
>
> DROP TABLE IPI_;
>
>
>
> I believe that it would be necessary, only this:
> ALTER TABLE IPI
>     ADD CLASSFISCAL VARCHAR(12);
>
> ALTER TABLE IPI
>     ALTER CLASSFISCAL POSITION 4;
>
> Since I only added a column.
> I don't understand, why of the remaining of the code.
> CREATE TABLE IPI_, INSERT INTO IPI_,
> DROP TABLE IPI, etc

This depends on what platform you use. Some databases fully support
adding columns (e.g. MySQL), for some this can only be used under
specific conditions, and for some, there is no way of adding the
column except by re-creating the table as is done in the SQL that you
posted.

Tom

Mime
View raw message