Solved

How to get lastest incremented UNIQUEIDENTIFIER?

Posted on 2004-08-24
4
219 Views
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?

                                                                       Thanx,

                                                                       Adnan
0
Comment
Question by:kamran_khan
[X]
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
4 Comments
 
LVL 11

Accepted Solution

by:
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
SET @GUID = NEWID()
INSERT Item VALUES (@GUID,'Yak Hoof')
0
 
LVL 4

Expert Comment

by:davehilditch
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.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

734 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