Answer the question
In order to leave comments, you need to log in
Sql. How to update some fields in a table with some user id (not ai), and if there is no field, then create a new record?
Sql. How to update some fields in the table with a certain user id (not ai), and if there is no field with such id, then create a new record?
Answer the question
In order to leave comments, you need to log in
It depends on the Sql dialect, you can try this:
update your_table
set your_field =your_new_value
from your_table
where id = your_id
if @@rowcount = 0
insert your_table(id, your_field)
values (your_id, your_new_value)
UseMySQL INSERT ON DUPLICATE KEY UPDATE
INSERT INTO table (column_list)
VALUES (value_list)
ON DUPLICATE KEY UPDATE
c1 = v1,
c2 = v2,
...;
REPLACE INTO table
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question