I have to make a update which shall change a boolean field in a table. If the value is true the value should be set to false and opposite.
Im not sure how the not keyword works in SQL and the following doesnt seem to work:
Update tbl set 开发者_如何转开发field=!field where ID=1
The !
operator is called NOT
in SQL. Try this:
UPDATE tbl
SET field = NOT field
WHERE ID = 1
I have verified that this works on PostgreSQL, and it should work on any DB engine worth its salt.
Update tbl set ID=1 where field<>field
<>
is not equal operator in sql
精彩评论