1

For example, is it possible to use MyBatis to issue DDL(Alter table, Drop table) to database? For example, modify the table schema using alter table?

Adam Lee
  • 24,710
  • 51
  • 156
  • 236

1 Answers1

2

Yes it is possible. See this thread

You would do something like :

<update id="createNewTable" parameterType="String" > 

    #{value}; 

</update > 

Where the parameter is your 'create table' statement, using #{value} means your parameter will not be escaped.

If you just want to set the table name, you would do:

<update id="createNewTable" parameterType="String" > 

    CREATE TABLE IF NOT EXISTS #{value} ( 
            id             INT UNSIGNED        AUTO_INCREMENT PRIMARY KEY, 
    ENGINE=InnoDB DEFAULT CHARSET=utf8; 

</update > 

Here is nice answer for alter

VedantK
  • 9,728
  • 7
  • 66
  • 71