Question: How can I get the @@IDENTITY for a specific table?

I have been doing 

```
select * from myTable 

```

as I assume this sets the scope, from the same window SQL query window in SSMS I then run 

```
select @@IDENTITY as identt

```

It returns identt as null which is not expected since myTable has many entrie in it already..

I expect it to return the next available ID integer.

myTable has a ID column set to Primary key and auto increment.

Answer: 
You can use [IDENT\_CURRENT](http://msdn.microsoft.com/en-us/library/ms175098.aspx)

```
IDENT_CURRENT( 'table_name' )

```

Note that IDENT\_CURRENT returns the last identity value for the table **in any session and any scope**. This means, that if another identity value was inserted after your identity value then you will not retrieve the identity value that you inserted.
You can only truly use `SELECT @@IDENTITY` after an insert - the last insert into a table that has an IDENTITY column is the value you'll get back.

You cannot "limit" it to a table - the value in @@IDENTITY - and by the way, I'd **strongly recommend** using SCOPE\_IDENTITY() instead!! - is the last value on any IDENTITY column that was set.

The problem with @@IDENTITY is that it will report back the last IDENTITY value inserted into any table - if your INSERT into your data table will cause e.g. a trigger to write an entry into an Audit table and that Audit table has an IDENTITY field, you'll get back that IDENTITY value - not the one inserted into your table. SCOPE\_IDENTITY() solves that.