I have a table ImportHistory in which I store history of importation. (Each time the user upload a file I store a row).
CREATE TABLE [dbo].[ImportHistory]
(
[Id] INT IDENTITY (1, 1) NOT NULL,
[Date] TIMESTAMP NOT NULL,
CONSTRAINT [PK_ImportHistory] PRIMARY KEY ([Id])
)
And I have also
CREATE TABLE [dbo].[Sales] (
[Id] VARCHAR (150) NOT NULL,
...
[ImportHistoryId] INT NOT NULL,
...
CONSTRAINT [FK_Sales_ImportHistory] FOREIGN KEY ([ImportHistoryId]) REFERENCES [dbo].[ImportHistory] ([Id])
);
The question is how to properly take the ID of ImportHistory and store it each time I insert a line in SALES for this import session ?