Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to update an existing row in DB, using liquibase?

Tried to find an answer to this question, but couldn't.

So, for example I have this table:

TABLE:

col1 | col2
123       0
124       1

and I want to change col2 value to 1 and this is how I'm trying to do it:

<changeSet author="myName" id="7799">
        <sql>
        UPDATE TABLENAME;
        SET COL1='1' WHERE col1='123';
        </sql>
</changeSet>

Alas, it doesn't work. So, I was wondering if it is even possible to do that with liquibase? Since, most tags in the documentation have to do with creating table, adding columns etc.

like image 399
user2187935 Avatar asked May 20 '13 18:05

user2187935


1 Answers

You can use the following liquibase syntax to update:

<changeSet author="myname" id="7799">
    <update catalogName="dbname"
            schemaName="public"
            tableName="TABLENAME">
        <column name="COL1" value='1' type="varchar(50)"/>
        <where>col1='123'</where>
    </update>
</changeSet>

For the other options available please check Liquibase Update

like image 128
Mohammad Nadeem Avatar answered Sep 22 '22 01:09

Mohammad Nadeem