From the course: SQL Server 2008 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using the OUTPUT clause to return inserted keys and GUIDs

Using the OUTPUT clause to return inserted keys and GUIDs - SQL Server Tutorial

From the course: SQL Server 2008 Essential Training

Start my 1-month free trial

Using the OUTPUT clause to return inserted keys and GUIDs

It's very common that as you start inserting information into your databases, what you're going to need or at least what your applications are going to need is to find out a bit more information about what you just inserted. Particularly in the case where you are inserting information into a table that is going to generate keys for you, either identity columns like this one, ProductCategoryID just going up one by one, or guids that are being built as well or perhaps both at the same time. But in the INSERT example we saw before, all that I'm inserting is a ParentProductCategoryID and a name, because the guids and the identities are being generated for us. Now, we want to get that information after this INSERT has happened. This used to be a bit of a problematic thing to do. In fact often what you used to have to do is write little pieces of code to generate that guid yourself and then insert it yourself, so that you knew what it was. Well, it's a lot simpler these days. What we just…

Contents