English 中文(简体)
@@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT [sql server 2005]
原标题:

Which should i use to get last inserted record id in sql server 2005?

I searched stackoverflow and i found this,

SQL: How to get the id of values I just INSERTed?

Comment of the best answer:

there are known bugs with SCOPE_IDENTITY() in sql server 2005, not sure about 2008, the OUTPUT clause can return a set of IDs if necessary...

Select SCOPE_IDENTITY() as Id from Table

I am uisng sql server 2005... Any suggestion

最佳回答

I m not entirely sure what these "knows bugs" in SCOPE_IDENTITY() should be. The only thing I m currently aware of is here: Six reasons you should be nervous about parallelism mentioned as the very first point.

问题回答

Triggers

Using @@identity is reliant on the fact that there are no triggers in your database creating records elsewhere.

If you create a record but a trigger then creates a log entry for the creation, @@identity will return you the id of the log entry in the log table.





相关问题
SQL Server database is not visible

I have installed ASP.NET application with database on our server. ASP.NET application created database using connection string below. The problem is that I do not see database in SQL Server Management ...

Most efficient way to store number 11.111 in SQL Server

What datatype is the most efficient to store a number such as 11.111. The numbers will have up 2 digits before the point and up to three after. Currently the column is a bigint , I am guessing that ...

表格和数据表

是否需要在提瓜表之后更新表格统计数据,还是自动更新?

Inconsistent Generate Change Script

I add a column of type tinyint and being set to not allow nulls in a table and generate the change scripts. The table has data in it at this time. The script has code that creates a temp table and ...

Performance of Sql subqueriesfunctions

I am currently working on a particularly complex use-case. Simplifying below :) First, a client record has a many-to-one relationship with a collection of services, that is, a single client may have ...

selecting one value out of an xml column

I have a particularly troublesome xml column to query data from. The schema is fixed by the Quebec Ministry of Revenue so "it is what it is" The important part of the query looks like this: with ...

Selecting records during recursive stored procedure

I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...

热门标签