Reputation: 398
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?
Upvotes: 3
Views: 12022
Reputation: 37233
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);
Upvotes: 7