首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > PowerDesigner >

mysql_一个经典的update语句异常

2012-09-16 
mysql_一个经典的update语句错误一个经典的update语句错误 使用update语句可以更新(修改)表中的数据。 upda

mysql_一个经典的update语句错误

一个经典的update语句错误

 

使用update语句可以更新(修改)表中的数据。

 

update语句的语法为:

    UPDATE [LOW_PRIORITY] [IGNORE]tbl_name

   SET col_name1=expr1 [,col_name2=expr2 ...]

    [WHEREwhere_definition]

    [ORDER BY ...]

    [LIMITrow_count]

 

由“SETcol_name1=expr1 [, col_name2=expr2 ...]”可知,更新多个列时,只需要使用单个set命令,每个”列=值”对之间用逗号分隔。

 

例如:

将玩家等级c_level小于20的所有角色的经验c_exp设置为10000,等级c_level设置为20,可用:

update t_char set c_exp=10000, c_level = 20 where c_level < 20;

 

然而,在使用该语句时写成了:

 

update t_char set c_exp=10000and c_level = 20 where c_level < 20;

 

语句可以执行成功,但语句将被解析为:

 

update t_char set c_exp=(10000 and c_level = 20) where c_level < 20;

 

即c_exp设置为(10000 and c_level = 20),一个布尔值,在此例中c_exp将被设置为0。

逻辑AND:当所有操作数均为非零值、并且不为NULL时,计算所得结果为  1 ,当一个或多个操作数为0 时,所得结果为 0 ,其余情况返回值为 NULL 。

热点排行