Home >Database >Mysql Tutorial >mysql数据库id重复无法删除的解决方法_MySQL

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:34:591049browse

bitsCN.com

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

 

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

 

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

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

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

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

 

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

    

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

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

 

另外值得一提的是,这个语句知识mysql中,而标准sql语句中是没有的。

bitsCN.com
Statement:
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