Jump to content

Insert into...on duplicate key problem


incubator140

Recommended Posts

Hello All,

Donno you have faced such a problem. 

But I had a struggling day as it was not working for me, but I am able to find something which is interesting.

I have a table like this

 

CREATE TABLE `abc` (

  `a` int(11) UNSIGNED NOT NULL,

  `b` int(11) UNSIGNED NOT NULL,

  `c` varchar(50)  NOT NULL,

  UNIQUE (`a`)

) ENGINE=MyISAM;

And I am using the following query to insert a record or update if exist.

 

INSERT INTO abc (a,b,c) VALUES (1,200, 'test') ON DUPLICATE KEY UPDATE c='test'

 

unfortunately, that's not working. But the following is working well. (the difference is just the data type of field 'c')

 

CREATE TABLE `abc` (

  `a` int(11) UNSIGNED NOT NULL,

  `b` int(11) UNSIGNED NOT NULL,

  `c` int(50)  NOT NULL,

  UNIQUE (`a`)

) ENGINE=MyISAM;

 

INSERT INTO abc (a,b,c) VALUES (1,200, 300) ON DUPLICATE KEY UPDATE c=300

Can anyone tell me how to get rid of these problem ( I don't want to do it in two queries  )

Thanks in advance!

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.