Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql insert inserted id

-- Never use @@identity or scope_identity()
-- they can not always be relied upon

DECLARE @Ids_tbl TABLE ([id] INT); -- Requires table. use variable for scope
INSERT INTO [sometable] ([ColA],[ColB])
OUTPUT INSERTED.ID INTO @Ids_tbl(id)
VALUES ('valA','valB');

SELECT [id] FROM @Ids_tbl; -- <-- Id(s) in here

Comment

PREVIOUS NEXT
Code Example
Sql ::  
::  
::  
::  
Sql ::  
::  
::  
Sql :: mssql find deadlocks 
:: mysql start command 
:: order by sql 
Sql ::  
:: mysql timestamp to date 
::  
::  
:: postgres default user 
Sql ::  
::  
::  
::  
Sql ::  
Sql ::  
::  
::  
::  
::  
::  
::  
::  
::  
::  
ADD CONTENT
Topic
Content
Source link
Name
4+1 =