Home > Database > Mysql Tutorial > body text

MySQL数据库id重复无法删除的解决方法

WBOY
Release: 2016-06-07 17:29:10
Original
751 people have browsed it

由于好长时间没有搞数据库了,SQL语句忘了好多。 最近,要用到这方面的只是,这个是由于服务器后台使用Mysql来对数据进行存储数据

由于好长时间没有搞数据库了,SQL语句忘了好多。

最近,要用到这方面的只是,这个是由于服务器后台使用Mysql来对数据进行存储数据造成的,

为了要做个在线时间的统计的功能,服务端必须要记录一些时间段的用户在线情况。

其实,实现起来不是很难,但是多条线的情况时,可能会涉及多个服务器对数据库的写入,这个时候,如果

id是有上层来确定是很困难的。所以呢,应该做成自动更新id的方式。

例如,如果列a被定义为unique,并且值为1,,则下列语句有同样的效果,也就是说一旦出入的记录中存在a=1的情况,直接更新c = c + 1,而不执行c = 3的操作。

insert into table(a, b, c) values (1, 2, 3) on duplicate key update c = c + 1;

update table set c = c + 1 where a = 1;

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!