Questions tagged [scope-identity]
122 questions
4
votes
3 answers
T-SQL: returning the new INSERT identity to C#
i'm putting values into SQL Server using a Stored Procedure. The Procedure will add an ID to the row that is added. I need to get this ID back to my code.
Currently I can get the I see the output id in the OUTPUT window of Visual Studio, but can't…

Tomasz Iniewicz
- 4,379
- 6
- 42
- 47
4
votes
1 answer
Pass scope_identity into a stored procedure
There are a lot of discussions about passing a scope_identity from a child to parent stored procedures. I have an opposite scenario where the row is inserted at parent stored procedure and I want to pass the identity value to a child stored…

intangible02
- 993
- 1
- 9
- 19
3
votes
2 answers
IDENT_CURRENT returns the last identity value but SCOPE_IDENTITY does not
I have a SQL Server as backend for an asp.net application. Multiple people might insert data in the same table 'the same time...'.
When I read the solution/answer from this post: scope_identity vs ident_current
THEN I should not use the…

Pascal
- 12,265
- 25
- 103
- 195
3
votes
1 answer
SQL insert ID from IDENTITY ID of the row being inserted
I would like to know, if there is a direct way to insert ID (generated at ID column with IDENTITY(1,1)) to another columns.
In another words, I am looking for SCOPE_IDENTITY() I could get at the time of inserting, not after the INSERT is commited.
I…

Oak_3260548
- 1,882
- 3
- 23
- 41
3
votes
3 answers
SQL Scope_Identity is returning 0 or -1
I'm having issues getting the last row affected ID, it's returning 0, this means that it has an error on format being inserted. I executed the stored procedure and added the values manually, it return'd the correct ID. But when I try to do it with…

datalekz
- 129
- 1
- 14
3
votes
3 answers
How can i take last inserted PK computed varchar(7) field as output
DDL:
CREATE TABLE [dbo].[Admin_Profile](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Ad_Regid] AS ('R'+right('200'+CONVERT([varchar](10),[ID],(0)),(6))) PERSISTED NOT NULL,
[Ad_Fname] [varchar](25) NULL,
[Ad_Lname] [varchar](25) NULL,
…

user72
- 141
- 1
- 2
- 9
3
votes
3 answers
asp.net InsertCommand to return latest insert ID
I'm unable to retrieve the latest inserted id from my SQL Server 2000 db using a typed dataset in asp.NET
I have created a tableadapter and I ticked the "Refresh datatable" and "Generate Insert, Update and Delete statements". This auto-generates the…

Stijn Van Loo
- 451
- 7
- 21
3
votes
2 answers
C# Scope_Identity Issue
Browsed some answers and doesn't appear to be working for me.
I need the ID field of a table to be returned so I can use it in a different part of the program, I've tried using
Convert.ToInt32(sqlComm.ExecuteScalar());
But no luck, and same…

ZeeeeeV
- 361
- 3
- 11
- 25
3
votes
2 answers
SQL Server 2012 scope_identity advise
I created a stored procedure in SQL Server 2012 and I have used scope_identity to get identity column's value but in my case I do not know is this correct or not please help
CREATE PROCEDURE Add_Translation
@english nvarchar(70),
@kurdish…

danarj
- 1,798
- 7
- 26
- 54
2
votes
1 answer
Correct way/location to use Scope_Identity()
I have an auto incrementing ID called deviceID in one of my fields. I was wanting to pass this to a session in php to use later on and was planning on using scope_identity() as I understand that this is the best way to get the current Primary key…

b.man
- 41
- 3
2
votes
2 answers
Trying to use "Scope_Identify()" in a stored procedure from a method in a C# class to get the ID of the resultant insert
I have a stored procedure for inserting a record in a table. I'm trying to use Scope_Identity() to get back the created ID value. I call the procedure from a method named Add_Claimant(). The method inserts a claimant into the table fine, but I am…

MIkeN
- 21
- 2
2
votes
1 answer
How to use scope identity in SQL Command?
My concept for using the scope identity is given below. What is the proper way to use the scope identity that support my concept?
For single data:
Imports System.Data.SqlClient
Public Class Class1
Sub Something()
Using con As…

nightfire001
- 759
- 3
- 20
- 50
2
votes
3 answers
nextval and curval confusion in PostgreSQL
What will happen if multiple user run the following query at the same time?
INSERT INTO…

nightfire001
- 759
- 3
- 20
- 50
2
votes
1 answer
NHibernate: Insert entity with identity value set on a different column
Is it possible with NHibernate and Sql Server to insert an entity and set one of the column values to the newly generated identity?
In pure sql I can do it by adding the default value
Create the table:
create table Test
id int identity,
name…

MonkeyCoder
- 2,600
- 2
- 28
- 30
2
votes
1 answer
how do I use the Identity_Scope as a value to insert in table in SQL Server
Ive looked over and over again for help but nothing has helped, I have a stored procedure where i want to insert the last identity ie SCOPE_IDENTITY() as B but it keeps returning a NULL value
CREATE PROCEDURE dbo.Createletter
@A INT,
@B…

Derek
- 47
- 1
- 9