简体   繁体   中英

MySQL - Replace Column Value

I want to update/replace two column's value in a time.

UPDATE table_messages SET id_msg = 4, numbers_msg = 50;

and:

INSERT INTO table_messages (number_msg, id_msg) VALUES (50, 4);

mysql said: #1062 - Duplicate entry '4' for key 'PRIMARY'

both not working, what's the problem? any other command?

your id_msg cant be duplicated because its primary key . you maybe interested to just update numbers_msg .

like that:

    UPDATE table_messages SET  numbers_msg = 50 WHERE id_msg = 4 ;

Or :

delete old id_msg = 4 and then use your query.

   INSERT INTO table_messages (number_msg, id_msg) VALUES (50, 4);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM