Linked Questions
36 questions linked to/from SQL Server - Return value after INSERT
1
vote
2
answers
440
views
How to retrieve SCOPE_IDENTITY of all inserts done in INSERT INTO [table] SELECT [col1, ...] [duplicate]
Suppose I have a temp table with some cols one of which I have dedicated to identity column of the inserted Invoice and the others for inserting Invoice data itself. Like the following table :
CREATE ...
-1
votes
2
answers
206
views
SQL sever, get the number associated with the last inserted primary key [duplicate]
I have a table where it auto increment the primary key. I want to know the last instead primary key's number(which is always the primary key with the biggest value). I can't do this by counting the ...
1389
votes
15
answers
1.3m
views
How to get the identity of an inserted row?
How can I get the IDENTITY of an inserted row?
I know about @@IDENTITY and IDENT_CURRENT and SCOPE_IDENTITY, but don't understand the implications or impacts attached to each. How do these differ, and ...
367
votes
17
answers
326k
views
SET NOCOUNT ON usage
Inspired by this question where there are differing views on SET NOCOUNT...
Should we use SET NOCOUNT ON for SQL Server? If not, why not?
What it does Edit 6, on 22 Jul 2011
It suppresses the "xx ...
86
votes
5
answers
154k
views
PreparedStatement with Statement.RETURN_GENERATED_KEYS
The only way that some JDBC drivers to return Statement.RETURN_GENERATED_KEYS is to do something of the following:
long key = -1L;
Statement statement = connection.createStatement();
statement....
47
votes
7
answers
208k
views
Sql Server return the value of identity column after insert statement
Is it possible in sql server using stored procedure to return the identity column value in a table against which some values are inserted? For example using stored procedure if we insert data in a ...
26
votes
6
answers
25k
views
Instead of trigger in SQL Server loses SCOPE_IDENTITY?
I have a table where I created an INSTEAD OF trigger to enforce some business rules.
The issue is that when I insert data into this table, SCOPE_IDENTITY() returns a NULL value, rather than the ...
15
votes
3
answers
27k
views
Store the value of output inserted._ID to local variable to reuse it in another query
I want to simply execute a SQL query that would return the current id of the row that was added to a table, example:
insert into V_Post output inserted._ID values('Please return the id of THIS row :)'...
7
votes
8
answers
25k
views
Get Id after an INSERT in SQL Server in a multithread enviromment?
How can I get id after an INSERT in SQL Server ?
For my insert, I use context.ExecuteStoreCommand()
Warning: I have a multi-threaded application which inserts "at the same time" some data in the ...
11
votes
2
answers
14k
views
Best way to get PK Guid of inserted row
I've read this question about getting the identity of an inserted row. My question is sort of related.
Is there a way to get the guid for an inserted row? The table I am working with has a guid as ...
2
votes
2
answers
9k
views
How to get last inserted id on ms sql server with FireDac component?
with FireDac, How to get last inserted id on ms sql server?
thanks
1
vote
5
answers
7k
views
SQL Get the row number of the inserted row
I am trying to get the row number of an inserted record so I can use it for a select statement. What I am trying to accomplish is insert a person into one table, get that row number and then select ...
2
votes
4
answers
2k
views
Object reference not set to an instance of an object Error thrown?
I am a beginner in c#. I try to get the last inserted id from an update query. But i get an error
This is my code
String Query1 = "insert into test(userid,score) values ('"+userid+"',0);";
...
4
votes
2
answers
1k
views
How to store the value of last inserted id(PK) into a variable where the primary key is a GUID in VB.Net
My question is related to the question asked in here How to get last inserted id?
But the scope_identity() will not work for me as in my case the primary key value for the table is a GUID value.
...
0
votes
2
answers
2k
views
If Not Exists Insert inside a loop which record updated
Using SQL Server 2016, I have a very simple IF NOT Exists ..... INSERT statement inside a loop. This works well, as expected. Is there a way to identify which records existed therefore did not insert ...