title: How should I migrate this data into these Sql Server tables?
body: <p>I  wish to migrate some data from a single table into these new THREE tables.</p>
  <p>Here's my destination schema:</p>
  <p><img src="https://i.stack.imgur.com/6fPmI.png" alt="alt text" /></p>
  <p>Notice that I need to insert into the first <code>Location</code> table .. grab the <code>SCOPE_IDENTITY()</code> .. then insert the rows into the <code>Boundary</code> and <code>Country</code> tables.</p>
  <p>The <code>SCOPE_IDENTITY()</code> is killing me :( meaning, I can only see a way to do this via <code>CURSORS</code>. Is there a better alternative?</p>
  <h3>UPDATE</h3>
  <p>Here's the scripts for the DB Schema....</p>
  <p><strong>Location</strong></p>
  <pre><code>CREATE TABLE [dbo].[Locations](
      [LocationId] [int] IDENTITY(1,1) NOT NULL,
      [Name] [nvarchar](100) NOT NULL,
      [OriginalLocationId] [int] NOT NULL,
   CONSTRAINT [PK_Locations] PRIMARY KEY CLUSTERED 
  (
      [LocationId] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
  ) 
  </code></pre>
  <p><strong>Country</strong></p>
  <pre><code>CREATE TABLE [dbo].[Locations_Country](
      [IsoCode] [nchar](2) NOT NULL,
      [LocationId] [int] NOT NULL,
   CONSTRAINT [PK_Locations_Country] PRIMARY KEY CLUSTERED 
  (
      [LocationId] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  
  GO
  
  ALTER TABLE [dbo].[Locations_Country]  WITH CHECK ADD  CONSTRAINT [FK_Country_inherits_Location] FOREIGN KEY([LocationId])
  REFERENCES [dbo].[Locations] ([LocationId])
  GO
  
  ALTER TABLE [dbo].[Locations_Country] CHECK CONSTRAINT [FK_Country_inherits_Location]
  GO
  </code></pre>
  <p><strong>Boundary</strong></p>
  <pre><code>CREATE TABLE [dbo].[Boundaries](
      [LocationId] [int] NOT NULL,
      [CentrePoint] [varbinary](max) NOT NULL,
      [OriginalBoundary] [varbinary](max) NULL,
      [LargeReducedBoundary] [varbinary](max) NULL,
      [MediumReducedBoundary] [varbinary](max) NULL,
      [SmallReducedBoundary] [varbinary](max) NULL,
   CONSTRAINT [PK_Boundaries] PRIMARY KEY CLUSTERED 
  (
      [LocationId] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  
  GO
  
  SET ANSI_PADDING OFF
  GO
  
  ALTER TABLE [dbo].[Boundaries]  WITH CHECK ADD  CONSTRAINT [FK_LocationBoundary] FOREIGN KEY([LocationId])
  REFERENCES [dbo].[Locations] ([LocationId])
  GO
  
  ALTER TABLE [dbo].[Boundaries] CHECK CONSTRAINT [FK_LocationBoundary]
  GO
  </code></pre>