Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

altering my sql table to add multiple new columns at once using liquibase

Tags:

liquibase

What is the correct syntax to alter the table and adding multiple columns at a time using liquibase xml. The official document gives the example for adding only one column :

<changeSet author="liquibase-docs" id="addColumn-example">
    <addColumn catalogName="cat"
            schemaName="public"
            tableName="person">
        <column name="address" type="varchar(255)"/>
    </addColumn>
</changeSet>

Now if I want to add multiple columns at a time, what is the correct syntax:

<changeSet author="liquibase-docs" id="addColumn-example">
    <addColumn catalogName="cat"
            schemaName="public"
            tableName="person">
        <column name="job" type="varchar(255)"/>
    </addColumn>
    <addColumn catalogName="cat"
            schemaName="public"
            tableName="person">
        <column name="designation" type="varchar(255)"/>
    </addColumn>
</changeSet>

Is it correct or

<changeSet author="liquibase-docs" id="addColumn-example">
    <addColumn catalogName="cat"
            schemaName="public"
            tableName="person">
        <column name="job" type="varchar(255)"/>
       <column name="designation" type="varchar(255)"/>
    </addColumn>   
</changeSet>

which is correct of the two above? or something different altogether.

like image 405
smart987 Avatar asked Oct 08 '15 17:10

smart987


People also ask

How do you add multiple columns using alter in SQL?

You can add multiple columns to an SQL table using the ALTER TABLE syntax. To do so, specify multiple columns to add after the ADD keyword. Separate each column you want to add using a comma.

Can we add multiple columns in ALTER TABLE in MySQL?

I recently needed to add multiple columns to an existing table to store summary data calculations and wondered if I could do it in one MySQL ALTER TABLE statement. Turns out you can. And, it's super simple.

What is a change set in Liquibase?

The changeset tag is a unit of change that Liquibase executes on a database and which is used to group database Liquibase Change Types together. A list of changes created by multiple changesets are tracked in a changelog.


1 Answers

Both of those examples will work.

like image 190
SteveDonie Avatar answered Oct 18 '22 15:10

SteveDonie