Jump to content

Mysql insert multiple data issue


laxi

Recommended Posts

Hi everyone,

I am trying to insert multiple data into my mysql database table with the below syntax.

however it only inserts the first row of data and returns a syntax error. Not sure what i am doing wrong...Please advice
-------------------------------------------
INSERT INTO three_drops ( id, tier_one,tier_two, tier_three)
VALUES



(4, 'CLOTHING', 'MEN', 'Jeans');
(5, 'CLOTHING', 'MEN', 'Cargos');
(6, 'CLOTHING', 'MEN', 'Shorts & 3/4ths');
(7, 'CLOTHING', 'MEN', 'Trousers');

-------------------------------------------------

it inserts only 4th item and returns an error for the remaing items

Error

SQL query:

( 5, 'CLOTHING', 'MEN', 'Cargos' ) ;


MySQL said:
#1064 - 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 '5, 'CLOTHING', 'MEN', 'Cargos')' at line 1



Viewing: Dev Shed Forums > Databases >

Link to comment
Share on other sites

As a side note: be carefull when inserting multiple values at once in MySQL, some versions don't rollback so when the third set of values fails to insert, the first two may have made it into the table already and are not removed (even though when an insert query fails you'd expect none of the data to be saved).

 

Test this error on your database before using this method in production. (and ofcourse always use InnoDB and transactions!)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.