MS Access:

  insert语句;

  select @@identity; 

  -- 但是要分成两次查询。

MS SQL Server:

  insert语句;

  select @@identity;或者:select scope_identity();

  -- 可以把两条语句一起执行。

Oracle:

  select 序列名.nextval from dual;

  insert into 表名 (序列字段,...) values (序列名.nextval,...);

MySQL:

  insert 语句;

  select @@identity; 或者:select last_insert_id();

  -- 需要注意:当使用insert语句插入多条记录时,使用last_insert_id()返回的还是第一条的ID值,而@@identity返回的是最后一条的ID值。

posted on 2012-10-01 13:59  萨迦狐  阅读(140)  评论(0)    收藏  举报