sql - MySQL - Create an UNIQUE index on two columns for ON DUPLICATE KEY -


I have a table with 4 columns, I want to be able to update the INSERT or the value column of the build (I Does not care about index queue ID).

  CREAT table Tablename (id, (primary) user_id, (index) Setting_id, (index) value (index));  

Originally I wanted to save a value, whenever I ran the query "One place ..." But then I chose it and instead of an INSERT ... on duplicate key updates.

The problem is that I do not have a single column for "INSERT ... ... duplicate key update to use" to find out whether it is a new line or if the current row Need updates in

So I thought I would use a unique key that was a mix of two columns, create unique index index_name on the line unique (

  table (user_id, setting_id);  

However, I'm not sure how to proceed from here. To test this new INDEX while trying to find an already existing line with these two column values Do I organize my questions?

  `tablename`  

: On the key update of INSERT VALUES (1, 34,15) duplicate values ​​(value, user_id, setting_id):

ID to the primary primary column I was able to create a primary index on (settings_ id, user_id) except by setting (settings_id, user_id, and value) and then the following query works.

  INSERT Tablename (user_id, Setting_id, value) Duplicate Key Update value =>  

on values ​​(42, 1, 12) P> Something like this in your query Dry will ...

  sign in table (price, User_id, Setting_id) Price (L,34, 15) duplicate key update value = 1, user_id = 34, Seting_aid = 15;  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -