I have a Sql table called MACHINES having few rows and columns, for example MachineId, MachineName, ProgramName, RightCount and FinishingTime. The values are read from a text file (xyz.txt) and inserted into this table. Every time the row gets updated when new values are read in this text file. My question is how can i make an extra table having a history of this MACHINES table. So that i can keep a track of it, in case if my RightCount value in textfile is changed from 3 to 4. The row in the 'MACHINES' table gets updated, but keeps a history for an example in MachineId 4 something changed. My overall goal is not to have Table 'MACHINES' with so much data when everytime my text file data gets changed. It takes my database space. Is it something to do with a foreign key. A SQL script for this procedure would be very helpful. Thank you so much.
I tried -> but was not able to have data in my history table when it got updated.
CREATE TABLE try.dbo.MACHINES
(MachineId bigint IDENTITY(1,1) PRIMARY KEY,
MachineName varchar(50) NOT NULL,
ProgramName varchar(255) NOT NULL,
RightCount int,
FinishingTime varchar(255) NULL,
);
CREATE TABLE try.dbo.MACHINES_HISTORY
(MachineStatusHistoryId bigint IDENTITY(1,1) PRIMARY KEY,
MachineId bigint NOT NULL,
CONSTRAINT FK_StatusHistory_Machines
FOREIGN KEY (MachineId)
REFERENCES dbo.MACHINES (MachineId),
);