在MySQL中插入和更新单个行表的最佳方法是什么? [英] What is the best way to insert into and update a single row table in MySQL?

查看:62
本文介绍了在MySQL中插入和更新单个行表的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只包含一行的MySQL表.第一次插入此行以及以后的更新时,语句应该是什么?我尝试了一个主键等于1的插入,但这在没有行存在的情况下并没有第一次解决.

I have a MySQL table that will only have one row. What should my statement be for the first time I insert to this row, and for subsequent updates? I tried an insert where the primary key equals 1, but this doesn't account for the first time around when no row exists yet.

推荐答案

INSERT INTO table(col1,col2,col3) VALUES(val1,val2,val3) ON DUPLICATE KEY UPDATE col1 = val1, col2 = val2, col3 = val3;

这篇关于在MySQL中插入和更新单个行表的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆