2012-06-18 114 views
2

我想做一个简单的mysql更新语句,或者至少我认为这是一个简单的更新语句。它正在执行成功,但它不匹配的条件是指定,并不会更新表...任何人都可以看到我做错了什么?MySQL的更新声明不能按预期工作

update messagequeue set timesent = curtime() where deviceid = '1231231237' and timesent = NULL 

表中有4列和1行。

id, message, deviceid, timesent 

the timesent is default null. 
the deviceid is '1231231237' 
id = 1 
message is just some junk.... 

查询只是不工作:(

回答

3
update messagequeue set timesent = curtime() where deviceid = '1231231237' and timesent IS NULL 
1

权。 '=' 不与NULL工作,所以你应该使用 'IS NULL' 作为Sebas的答案。

1
UPDATE messagequeue SET timesent = curtime() WHERE deviceid = '1231231237' AND timesent IS NULL 

NULL不会按照你的定义工作,而是使用IS NULL检查

另外检查数据类型'deviceid'如果是Int,那么不要用sing le引用它,像这样使用它:

UPDATE messagequeue SET timesent = curtime() WHERE deviceid = 1231231237 AND timesent IS NULL