0

Original Question

MySQL workbench allows one to define "inserts": rows to be inserted into the database on creation. It does this by adding lines such as

START TRANSACTION;
USE `someDB`;
INSERT INTO `someDB`.`countries` (`name`) VALUES ('South Africa');

COMMIT;

However, if the database, table and entry exists, this throws an error. Creation of tables does not, as workbench uses CREATE IF NOT EXISTS for those. Is there a way to get workbench to insert using INSERT...ON DUPLICATE KEY UPDATE?

Half Solution

Running the script with the force argument:

mysql user=xx password=xx --force < script.sql

Ignores such errors, and is thus a solution in my particular case. However, the actual question of modifying the type of INSERTS still stands (for interest)

See here

9
  • Not sure I follow. If this insert happens on database or table creation, how could there be pre-existing rows in any tables? Commented Apr 7, 2015 at 20:15
  • What are you trying to update? The point is that you have a unique key on countries. I expect you're not trying to create duplicates. If it gives you an error, you can always choose to ignore said error (which is how this kind of thing typically works). Commented Apr 7, 2015 at 20:15
  • @MikeBrant It is possible that the table exists, and is populated, hence why the CREATE IF NOT EXISTS is important. @john-green: Yes. This suffices. Commented Apr 7, 2015 at 20:24
  • Would you mind giving us a little more context? Where are you creating the inserts? Commented Apr 7, 2015 at 20:27
  • @Snivs Not quite sure what you are asking, but the inserts are being created under the "inserts" tab of a table in an ER diagram? Commented Apr 7, 2015 at 20:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.