Bug #51107 "Add table" with a table name that already exists fails silently
Submitted: 11 Feb 2010 15:01 Modified: 21 May 2010 15:39
Reporter: Greg Thomas Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Workbench: SQL Editor Severity:S3 (Non-critical)
Version:5.2.15 Revision 5053 OS:Any
Assigned to: Sergei Tkachenko CPU Architecture:Any

[11 Feb 2010 15:01] Greg Thomas
Description:
If you use the "Add table" facility to add a table with a name that already exists, it appears to work (and indeed you end up with two tables with the same name shown under "Tables") - however any information you added on the second table is silently lost.

How to repeat:
1. Create a table "test". Just give it a single column (e.g. idtest INT).

2. Use the "Add table" link to add a second table, also called "test". Give it more than one column (e.g. idtest INT and idtest2 INT).

Click Apply, Apply SQL. The dialogue indicates that the script was successfully applied. 

3. Click Finish and examine the tables in the "Overview". Two tables will exist called "test". Both are the first table that was created. Any columns etc. added to the second "test" are lost.

Suggested fix:
The table editor generates the code ...

CREATE  TABLE IF NOT EXISTS `test`.`test` (

  `idtest` INT NOT NULL ,
  `idtest2` INT NOT NULL ,

  PRIMARY KEY (`idtest`) );

Suggest instead that this is changed to ...

CREATE  TABLE `test`.`test` (
etc. etc.

so an error is presented if a table with that name already exists, alerting the user to the problem.
[11 Feb 2010 15:18] Greg Thomas
[Add missing version number]
[21 May 2010 10:23] Johannes Taxacher
fix confirmed in repository
[21 May 2010 15:39] Tony Bedford
An entry has been added to the 5.2.22 changelog:

In the SQL Editor, if the Add Table facility was used to create a new table with the same name as an existing table, then after changes were applied, the content of both tables was the same as the existing table, and changes unique to the second table were lost.