sql db record number

Over on Experts Exchange someone asked, once I insert a record into the table, how can I retrieve the primary key that was just inserted.  This is a topic I covered back in 2005 in my post SQL 101 – System Functions.  In this post I introduced you to @@IDENTITY.  If you are unfamiliar with the @@IDENTITY function, please check out my post.  This is a very useful technique to master!

This system function will tell you the id that was just created for your previous insert statement.  It looks like pollock_d and I were on the same page.  Unfortunately, it took a while before the author chose the expert answer.  Read through the process it took to get to the solution, It definitely shows how competitive some people are about getting credit for answers on Experts Exchange.

So, if you have questions, you’ll certainly get help there!

As for me, as long as you get an answer and understand why the answer works, you’ll learn from it.  That’s all that really matters is people learn a new skill in SQL.  If you have any questions about SQL, send them in.  I’m here to help!

Reference

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_23093384.html

By Shannon Lowder

Shannon Lowder is the Database Engineer you've been looking for! Look no further for expertise in: Business Analysis to gather the business requirements for the database; Database Architecting to design the logical design of the database; Database Development to actually build the objects needed by the business logic; finally, Database Administration to keep the database running in top form, and making sure there is a disaster recovery plan.

0 comments

Leave a comment

Your email address will not be published. Required fields are marked *