I have a new database on Microsoft SQL Server 2019 Express.
The tables are:
CREATE TABLE tbl1SalesOrders (
SalesOrderID INT NOT NULL IDENTITY(1,1),
SalesOrderCode NCHAR(11) NOT NULL UNIQUE DEFAULT dbo.GetNextCode_SalesOrder(),
SalesOrderDate DATE NOT NULL DEFAULT GETDATE(),
CONSTRAINT PK_tbl1SalesOrders PRIMARY KEY (SalesOrderID),
);
CREATE TABLE tbl1SalesOrderDetails (
SalesOrderDetailID INT NOT NULL IDENTITY(1,1),
SalesOrderID INT NOT NULL FOREIGN KEY REFERENCES tbl1SalesOrders (SalesOrderID) ON DELETE CASCADE,
ProductVariantID INT NOT NULL FOREIGN KEY REFERENCES tbl1ProductVariants (ProductVariantID),
Quantity DECIMAL(6,2) NOT NULL,
UnitPrice DECIMAL(10,2) NOT NULL,
VATRate DECIMAL(3,2) NOT NULL,
Discount DECIMAL(3,2) NOT NULL,
ExpectedDelivery DATE NULL,
Warranty TINYINT NULL,
CONSTRAINT PK_tbl1SalesOrderDetails PRIMARY KEY (SalesOrderDetailID),
);
I have data in similar tables in another database (same server). I want to migrate this data to the new tables in the new database.
I am wondering how I should migrate the IDENTITY data, so they stay persistent? For example if SalesOrderID 10 has 3 items with Foreign Key SalesOrderID = 10, how do I make them stay together in the new DB?
Because I believe identity will start from scratch in the new database.
Thank you in advance.
Tomas