Hello, I'm using SQL Server 2005.
I am migrating data over from a current database (single table) to a new database (normalized - many tables). In the new database, I have a base table (let's call it "BaseTable"), and multiple other tables (let's call them "DependentA", and "DependentB"). Some of the data from the old database will go to BaseTable, and some will go to the other two. BaseTable has a one-to-one relationship with both DependentA and DependentB, using the Id of them as the foreign key.
So here's my question. How should I migrate the data over? Here is a query I've been trying, which is working except for one thing: the foreign keys in BaseTable for the other two are identical, instead or having a different one each.
Begin SQL:
BEGIN TRANSACTION
DECLARE @dep1Id int
DECLARE @dep2Id int
INSERT INTO DependentA (column1, column2) SELECT c1, c2 FROM OldDatabase.OldTable SELECT @dep1Id = Scope_Identity()
INSERT INTO DependentB (column3, column4) SELECT c3, c4 FROM OldDatabase.OldTable SELECT @dep2Id = Scope_Identity()
INSERT INTO BaseTable (column5, dependentTable1Id, dependentTablr2Id) SELECT c5, @dep1Id, @dep2Id FROM OldDatabase.OldTable
COMMIT