【问题标题】:syntax error using Last_insert_id()使用 Last_insert_id() 的语法错误
【发布时间】:2011-12-20 15:30:20
【问题描述】:

我正在尝试使用 last_insert_id() 插入语句,我想获取最后插入的 ID 并将其作为外键插入另一个表中。

这是声明:

String stt= "insert into Takes_lesson values (lid,sid) (LAST_INSERT_ID(),"+sid+");";

但出现语法错误,似乎是什么问题? 在此先感谢

【问题讨论】:

  • 你收到了什么错误信息?

标签: mysql sql


【解决方案1】:

关键字/操作数的顺序错误..

在执行INSERT 时,列规范应位于VALUES 关键字之前,将您的查询与以下内容进行比较:

INSERT INTO Takes_lesson (lid,sid) VALUES (LAST_INSERT_ID(), ... )

【讨论】:

  • @MarwanTushyeh 请记得投上一票,尽可能接受答案。谢谢,很高兴一切顺利!
猜你喜欢
  • 2018-12-09
  • 1970-01-01
  • 2018-12-14
  • 2012-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-24
  • 1970-01-01
相关资源
最近更新 更多