熟悉MySQL函数LAST_INSERT_ID;是否有类似的功能可以通过 ODBC 对 MS Access 数据库执行相同的查询?
在我的具体案例中,我使用 PHP+PDO 将行插入到 Access 数据库中,并且想知道每次插入执行时的最后一个主键值。
如果此功能不可用,是否有替代方案? (不改变数据库)
谢谢。
最佳答案
似乎Access 2000 或更高版本支持@@IDENTITY
属性。因此,您只需要在 INSERT 之后选择它的值:
select @@IDENTITY from myTable
请参阅 MSDN 链接:Retrieving Identity or Autonumber Values
简而言之:
[...] Microsoft Access 2000 or later does support the @@IDENTITY property to retrieve the value of an Autonumber field after an INSERT. Using the RowUpdated event, you can determine if an INSERT has occurred, retrieve the latest @@IDENTITY value, and place that in the identity column of the local table in the DataSet.
关于php - 从 Access 获取最后插入 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4135437/