在mysql中获取更新查询的语法错误

时间:2016-07-16 05:33:42

标签: mysql

错误:

> #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use
> near 'where `membership_num`='1'' at line 1

查询:

   UPDATE `MEMBERSHIP` 
    SET `member_id`= 2, 
        `sales_id`=1,
        `duration`='3 شهور',
        `start_date`='2016-10-16',
        `end_date`='2016-10-16',
        `membership_cost_before`=500,
        `discount`=0,
        `member_ship_cost` =500,
        `membership_type` ='Silver',
        `amout_done` =500,
        `amount_reminder` = 0,
        `trainer_id` = 
     WHERE `membership_num`=1

2 个答案:

答案 0 :(得分:1)

trainer_id = where membership_num=1

您必须指定trainer_id是什么。现在你只有一个没有任何内容的=符号,这就是语法错误。

答案 1 :(得分:1)

您忘记为trainer_id=设置值,因此在条件之前为trainer_id添加任何值,此处我将空值trainer_id=Null

尝试此查询

UPDATE `MEMBERSHIP` 
    SET `member_id`= 2, 
        `sales_id`=1,
        `duration`='3 شهور',
        `start_date`='2016-10-16',
        `end_date`='2016-10-16',
        `membership_cost_before`=500,
        `discount`=0,
        `member_ship_cost` =500,
        `membership_type` ='Silver',
        `amout_done` =500,
        `amount_reminder` = 0,
        `trainer_id` =NULL 
     WHERE `membership_num`=1

注意:如果要为此更新空值,请确保在数据库结构中设置trainer_id列不为false。