8
Answers

How To get Last Inserted Records Guid Uniqueidentifier

Gagan Gautam

Gagan Gautam

8y
287
1
this is my query..
 
INSERT INTO Model (Id,Name,ValidationDate,NextValidationDate,DateCreated,DateUpdated,BusinessGroup,Country,UserId,StatusId,Deleted,RejectionNote)
SELECT Id,Name+'Copy',ValidationDate,NextValidationDate,DateCreated,DateUpdated,BusinessGroup,Country,UserId,StatusId,Deleted,RejectionNote FROM Model
where Id=@modelId
 
 {Id will be Print  on this section}
 
after inserting the record in this table i want to get Id (first Coloumn).
Answers (8)
1
ketan borsdiya

ketan borsdiya

NA 1.5k 3k 8y
Check below example
CREATE TABLE dbo.GuidTest (
Id uniqueidentifier NOT NULL DEFAULT NewSequentialID(),
Name varchar(20) NOT NULL
)
GO
INSERT INTO GuidTest(Name)
OUTPUT inserted.Id
VALUES('Ketan')
0
Gagan Gautam

Gagan Gautam

NA 132 6k 8y
Yes Ketan Plz five me response ASAP
0
ketan borsdiya

ketan borsdiya

NA 1.5k 3k 8y
Means your ID column store GUID and you need last inserted guid?
 
0
Gagan Gautam

Gagan Gautam

NA 132 6k 8y
Hi Ketan ,
i am talking about for Guid Not For Simple Id
My column is Guid with Identity,
now my requirment is that ,
i want Guid for Latest inserted record in table
0
ketan borsdiya

ketan borsdiya

NA 1.5k 3k 8y
Hi Gagan,
--First create table
CREATE TABLE [dbo].[TBL_TestIdentity](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](50) NULL
) ON [PRIMARY]
GO
-- Run Below Query
Insert into [TBL_TestIdentity](Name)
SELECT 'Ketan'
SELECT @@Identity
If it is not help you then explain me your problem and what you want?
0
Gagan Gautam

Gagan Gautam

NA 132 6k 8y
Dear Ketan can you give me example for uniqueidentifier how to get this...
0
ketan borsdiya

ketan borsdiya

NA 1.5k 3k 8y
Put below sentence after insert
select @@IDENTITY
If Id have set Identity then it returns newly inserted row's ID
 
For Guid Uniqidentifier you may  use NEWID()


 
-1
Vinay Singh

Vinay Singh

NA 5.9k 126k 8y
Hi
check the query
Select Id,Name,ValidationDate,NextValidationDate,DateCreated,DateUpdated,BusinessGroup,Country,UserId,StatusId,Deleted,RejectionNot
 from Model