scope-identity

SCOPE_IDENTITY() for bulk insert in SSIS

点点圈 提交于 2020-01-17 09:09:51
问题 In SSIS, I am able to make an insert of rows and retrieve their SCOPE_IDENTITY using OLE DB Command Task which calls stored procedure, but this is not bulk insert, it's slow load. Is it possible to get id of inserted rows using bulk insert in SSIS? Example: When inserting Customer, first I have to insert record in Person table and then use this FK in Customer table. UPDATE: Here's a structure of Person and Customer tables that need to be populated from external source. One option is to have

SCOPE_IDENTITY() for bulk insert in SSIS

点点圈 提交于 2020-01-17 09:09:50
问题 In SSIS, I am able to make an insert of rows and retrieve their SCOPE_IDENTITY using OLE DB Command Task which calls stored procedure, but this is not bulk insert, it's slow load. Is it possible to get id of inserted rows using bulk insert in SSIS? Example: When inserting Customer, first I have to insert record in Person table and then use this FK in Customer table. UPDATE: Here's a structure of Person and Customer tables that need to be populated from external source. One option is to have

How to get Identity of new records INSERTED into table with INSTEAD OF trigger

≡放荡痞女 提交于 2020-01-14 09:20:20
问题 I am using an INSTEAD OF insert trigger on a table to set an incrementing version number on the row and also copy the row to a 2nd history/audit table. The rows are inserted to both tables without a problem. However, I am having trouble returning the new identity from the 1st table back to the user. Schema CREATE TABLE Table1 ( id INT IDENTITY(1,1) PRIMARY KEY, name VARCHAR(250) NOT NULL UNIQUE, rowVersion INT NOT NULL ) CREATE TABLE Table1History ( id INT NOT NULL, name VARCHAR(250) NOT NULL

SCOPE_IDENTITY() for GUIDs?

巧了我就是萌 提交于 2020-01-08 16:02:37
问题 Can anyone tell me if there is an equivalent of SCOPE_IDENTITY() when using GUIDs as a primary key in SQL Server? I don't want to create the GUID first and save as a variable as we're using sequential GUIDs as our primary keys. Any idea on what the best way to retrieve the last inserted GUID primary key? 回答1: You can get the GUID back by using OUTPUT. This works when you're inserting multiple records also. CREATE TABLE dbo.GuidPk ( ColGuid uniqueidentifier NOT NULL DEFAULT NewSequentialID(),

SCOPE_IDENTITY() for GUIDs?

安稳与你 提交于 2020-01-08 16:02:26
问题 Can anyone tell me if there is an equivalent of SCOPE_IDENTITY() when using GUIDs as a primary key in SQL Server? I don't want to create the GUID first and save as a variable as we're using sequential GUIDs as our primary keys. Any idea on what the best way to retrieve the last inserted GUID primary key? 回答1: You can get the GUID back by using OUTPUT. This works when you're inserting multiple records also. CREATE TABLE dbo.GuidPk ( ColGuid uniqueidentifier NOT NULL DEFAULT NewSequentialID(),

Scope_identity() in batched sqlclient commands

北城余情 提交于 2019-12-31 05:01:06
问题 I usually use a stored procedure when inserting records to make sure I get the correct scope_identity() value. I have a requirement to get the id field of an inserted record when using SqlClient now. My understanding is that if I batch the scope_identity() command with the insert then it will still be in the same scope as the insert command? Something like below. Hard to verify though... Will I 100% get the correct id value with this..? (id field is an auto-incrementing bigint - Sql Server)

Fetch scope_identity value in C# code from stored procedure in 3 tier architecture

不打扰是莪最后的温柔 提交于 2019-12-28 07:08:12
问题 I need to fetch scope_identity() value from a stored procedure after inserting data in C# code. Here I am using 3 tier architecture. Please anyone help me protected void Submit_Click(object sender, EventArgs e) { this.CreateUserGroups(strGroupName, strDescription, strGroupType); } protected void CreateUserGroups(string strGroupName, string strDescription, string strGroupType) { string strReturn = string.Empty; strReturn = objUser.SaveCreateGroups(strGroupName, strDescription, strGroupType); }

Inserting into Oracle and retrieving the generated sequence ID

混江龙づ霸主 提交于 2019-12-28 03:36:07
问题 I have a handful of raw SQL queries for SQL Server which use SCOPE_IDENTITY to retrieve the generated ID for a specific INSERT immediately after that INSERT occurs all in one execution… INSERT into Batch( BatchName, BatchType, Source, Area ) Values ( @strBatchName, @strType, @strSource, @intArea ); SELECT SCOPE_IDENTITY() BatchID; The question is: What’s the best way to do that for an Oracle database? Can this be done on Oracle through standard SQL or do I have to switch this to use a stored

Trying to pass recent ID with scope_identity, and its error me : Specified cast is not valid

假装没事ソ 提交于 2019-12-24 07:37:36
问题 Im trying to pass the recent ID that I just insert with Scope_Identity, and its giving me some weird stuff. it says : : Specified cast is not valid and refering to the line : int IdOfRecentHistoryGame = (Int32)commandquery.ExecuteScalar(); this is the rest of the code : string username = Session["Session"].ToString(); con = new SqlConnection("Data Source=MICROSOF-58B8A5\\SQL_SERVER_R2;Initial Catalog=Daniel;Integrated Security=True"); con.Open(); string knowWhichOne = "SELECT ID FROM Users