N P
asked on
SQL Server IDENT_CURRENT
I am trying to find out what my last primary key was on a table, but I am getting the following error. I need to know that last key so that I can insert a new record with next correct primary key value
SELECT IDENT_CURRENT(dbo.Person)
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "dbo.Person" could not be bound.
nick
SELECT IDENT_CURRENT(dbo.Person)
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "dbo.Person" could not be bound.
nick
ASKER
Thanks Gohord, that worked, except I'm returning a null. After looking a the table, my last row shows PK_PersonID as 700940. I was going to use this value to increment by 1 and then insert new value into the table. Is my approach wrong or is this how a DBA typically inserts the next record? Sorry for asking dumb question, all my DBA's left.
nick
nick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, I appreciate the help
I would recommend using SCOPE_IDENTITY() vs @@Identity
because: if there is a trigger on a table that inserts a row on a second table
The second table id value is the @@identity returned.
IDENT_CURRENT is giving me some very unexpected results.
return 1 for a table with a thousand rows
because: if there is a trigger on a table that inserts a row on a second table
The second table id value is the @@identity returned.
IDENT_CURRENT is giving me some very unexpected results.
return 1 for a table with a thousand rows
select ident_current('dbo.Person'