Last post May 29, 2020 11:48 AM by email@example.com
May 29, 2020 08:02 AMfirstname.lastname@example.org|LINK
I have 2 tables, Table-A and Table-A-History.
I would like to have the most current row of my data in Table-A, and Table-A-History containing historical rows.
I can think of 2 ways to accomplish this:
whenever a new data row is available, move the current row from Table-A to Table-A-History and update the Table-A row with the latest data
(via insert into select or select into table)
insert into select
select into table
i want to use one trigger for all tables in db if any table inserted new row save that new row in
any delete happened also save it in Table-A-History
and any record updated which column updated save it in Table-A-History
May 29, 2020 09:10 AM|PatriceSc|LINK
Which SQL Server version do you have? Starting with SQL Server 2016 you have https://docs.microsoft.com/en-us/sql/relational-databases/tables/temporal-tables?view=sql-server-ver15 (and
it seems available as well in the Express edition).
If using an earlier version you could do something close (note in particular that you have columns to tell during which time frame the row was current).
Also it doesn't seems you really ask a question. If you want to help to get a single trigger for all tables it would be harder as you'll need to generate the SQL statement before running it (another option could be to generate the trigger code).
May 29, 2020 11:48 AMemail@example.com|LINK
except trigger can i do it by procedure or function?
can you write sample?