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
  • 23,314
  • 47
  • 144
  • 221

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

VeKe
  • 9,043
  • 5
  • 61
  • 67