I have a User table with a ReferenceId column, which points to a Reference table. Each user needs a ReferenceId which has to first be generated by an INSERT into a Reference table. The ReferenceId is a unique number that is different for each and every user.
User.ReferenceId = Reference.Id
User Table
+------------+----------+-------------+--+
| First Name | LastName | ReferenceId | |
+------------+----------+-------------+--+
| Bob | Smith | 123 | |
| John | Smith | 456 | |
+------------+----------+-------------+--+
Reference Table
+-----+----------+--+
| Id | Type | |
+-----+----------+--+
| 123 | External | |
| 456 | Internal | |
+-----+----------+--+
I will need to perform an operation to create two million users. I understand that if I create one user at a time sequentially, I can use the Output keyword to capture each generated ReferenceId, and then use it in my INSERT statement to the User table.
But is it possible to use batch/bulk operations here to improve performance so that I can create all the ReferenceIds in a single query, and then map all of them to a BULK INSERT to the User table, so that all new users can be created with their corresponding ReferenceIds in a single Query?