Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to get the last value added in my database?

Author  Topic 

haekz008
Starting Member

10 Posts

Posted - 2012-01-29 : 00:15:06
is there anyone who knows a query on how to get the last value that was added into the database?
for example :

i added a new item and i want to get the item id of new item that was added,.,

im hoping for your answers,.,thankyou guys

haekz008

mfemenel
Professor Frink

1421 Posts

Posted - 2012-01-29 : 06:22:10
Look at books online about @@identity and scope_identity. After doing an insert into a table with an identity column you can set a variable with either one of these and return it as an output.


Mike
"oh, that monkey is going to pay"
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-29 : 07:20:38
Also look up the OUTPUT clause.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-29 : 14:51:40
see an example here for usage of OUTPUT clause to grab generated values for batch insertion

http://visakhm.blogspot.com/2010/04/using-xml-to-batch-load-master-child.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -