【问题标题】:How get the Id of inserted row in SQL [duplicate]如何在 SQL 中获取插入行的 ID [重复]
【发布时间】:2015-10-17 06:36:37
【问题描述】:

我的数据库表有 ID 列,它是一个自动增量整数。在向表中自动插入数据时,我需要在插入记录时获取 ID 的值。

例如:表员工 = |ID|姓名 |地址|

查询是:

insert into employee(NAME, ADDRESS) values("azzi", "test adress")

有可能我们可以在插入记录后立即更改此查询以返回 ID,有人可以帮我这样做。

【问题讨论】:

标签: sql sqlite sql-insert


【解决方案1】:

使用 SQLite last_insert_rowid() 函数:

last_insert_rowid() 函数从调用该函数的数据库连接返回最后一行插入的 ROWID。

【讨论】:

    【解决方案2】:

    SQLite

    这可以使用SQLite last_insert_rowid() function

    last_insert_rowid() 函数返回最后一行的 ROWID 从调用该函数的数据库连接中插入。这 last_insert_rowid() SQL 函数是对 sqlite3_last_insert_rowid() C/C++接口函数。

    资源:How to get last insert Id in SQLite?

    【讨论】:

      猜你喜欢
      • 2014-01-29
      • 1970-01-01
      • 2014-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-18
      • 2014-01-22
      相关资源
      最近更新 更多