Let's create a table and examine on a sample.
1- First option @@identity
select @@IDENTITY
As you can see it returns 3. But if you open a new query tab and execute select @@IDENTITY again. It returns NULL because @@identity returns the last generated identity value on the opened connection.
2-The other option is DBCC command.
dbcc checkident('dbo.News',noreseed)
Result Messages are:
Checking identity information: current identity value '3', current column value '3'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
3- The third option is ident_current function.
select IDENT_CURRENT('dbo.News')
The advantage of this version is that you can use in select query. In this option we should use information_schema.tables to list all tables' identities.
For example:
4- You can use sys.identity_columns system view to list all current identities.
Hiç yorum yok:
Yorum Gönder