문제

I got a problem. I use SQL Server 2008 Express.

When new row is inserted into a table the IDENT_CURRENT function returns correct value (last inserted row id). But when the last inserted row is deleted (DELETE FROM REPORT WHERE ID='last_inserted_id') the IDENT_CURRENT function returns id of the deleted row. It do not update.

I need to return the last id from the table.

SELECT IDENT_CURRENT('report')
도움이 되었습니까?

해결책

This is working as expected. The function returns the last identity value used, even if it's been deleted. Here's an excerpt from Microsoft's documentation:

IDENT_CURRENT returns the last identity value generated for a specific table in any session and any scope.

다른 팁

Identity always goes up. It won't go down if you delete rows. Plus it can have 'blanks' in values. Read this for detailes http://technet.microsoft.com/en-us/library/ms186775.aspx

If you want the max ID you can find in your table, just use

SELECT MAX(ID) FROM table
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top