I am working on an application which is written in Java. Now I have to create a new column in my Database. But the column shall just be created when it is not existing.
So I want to use IF NOT EXISTS and ALTER TABLE to create my new Column.
Here is what I tried:
//Some import statements and previous, not for the question relevant code
//relevant code:
Statement alter = conn.createStatement();{
String alterStr="alter table test_cm_documents ADD if not exists test_id int";
alter.executeQuery(alterStr);
System.out.println("Column has been generated.")
}
Actually I just expected that it prints out "Column has been generated." but it gives me the following error Message:
ERROR 1064(42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if not exists test_id' at line 1
I am quite new to the topic so please excuse any mistakes.