本文介绍了如何获取最后插入的主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将 SQL Server 2005 与一个主键字段类型为 varchar(40) 的表一起使用.我必须获取最后插入的记录的主键值.我尝试过 scope_identity 但它不起作用.我怎样才能得到这个?
I'm using SQL Server 2005 with a table with a primary key field with the type varchar(40). I have to get the last inserted record's primary key value. I have tried scope_identity but it is not working. How can I get this?
推荐答案我找到了结果.
代码:
insert into T output inserted.pk values ('new item');更多推荐
如何获取最后插入的主键?
发布评论