Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql get inserted primary key

CREATE TABLE #a(identity_column INT IDENTITY(1,1), x CHAR(1));
INSERT #a(x) VALUES('a');

SELECT SCOPE_IDENTITY();

-- 4 ways to get identity IDs of inserted rows in SQL Server
INSERT INTO TableA (...) VALUES (...)
SELECT @@IDENTITY

INSERT INTO TableA (...) VALUES (...)
SELECT SCOPE_IDENTITY()

SELECT IDENT_CURRENT('dbo.TableA')

DECLARE @NewIds TABLE(ID INT, ...)
INSERT INTO TableA (...)
OUTPUT Inserted.ID, ... INTO @NewIds
SELECT ...
Comment

PREVIOUS NEXT
Code Example
Sql :: primary key multiple colums 
Sql :: sqlite unique 
Sql :: sql server date format yyyy-MM-ddThh:mm:ss 
Sql :: spring boot working with sql database connection 
Sql :: mysql stored procedure vs function 
Sql :: Get first name and last name from full name string in SQL 
Sql :: c# sqldatareader to list 
Sql :: PostgreSQL types and C# types 
Sql :: MySQL get all previous date record 
Sql :: mysql delete database 
Sql :: sql round 2 decimal 
Sql :: add time to date sql 
Sql :: mariadb date equals to current_date plus days 
Sql :: Create boolean column in MySQL with false as default value? 
Sql :: sql log file inof 
Sql :: Index a database column sql 
Sql :: setval max id postgresql sequence 
Sql :: q operator in oracle 
Sql :: sql server select furst day of current year 
Sql :: run sql script from command line 
Sql :: sql server query database space available 
Sql :: sql display max value 
Sql :: mysql loop 
Sql :: truncate oracle 
Sql :: Cannot truncate a table referenced in a foreign key constraint (`video_clips`.`channel_clips`, CONSTRAINT `clips_fk` FOREIGN KEY (`clip_id`) REFERENCES `video_clips`.`clips` (`id`)) in sql] 
Sql :: oracle create table primary key 
Sql :: Selecting duplicates 
Sql :: sql select non unique 
Sql :: distinct in sql server 
Sql :: oracle generate list of dates in between a date range 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =