How to get lastest incremented UNIQUEIDENTIFIER?

Posted on 2004-08-24
Last Modified: 2012-05-05
Hello Everyone!
       As last inserted value can be got through "Select @@Identifier" if we are using INTEGER datatype but what if we use UNIQUEIDENTIFIER datatype, how do we get last inserted value?


Question by:kamran_khan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Accepted Solution

ram2098 earned 500 total points
ID: 11878604
There isn't a way to get the value of a uniqueidentifier column after an insert. You can get it before the insert, however, by using the below code.

DECLARE @GUID uniqueidentifier

Expert Comment

ID: 11880320
And additonally, you shouldn't really use @@IDENTITY in the first place, as if you have a trigger on the table which then inserts to another table you will receive the wrong value.  For identity columns, you should use scope_identity() instead.

Dave Hilditch.

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question