Solved

How to get lastest incremented UNIQUEIDENTIFIER?

Posted on 2004-08-24
4
218 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
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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

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.
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
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.

749 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