Ive got a task here to log changes in the database.
So Ive just read about Triggers and that made me interested to try that out.
I got this table in the database were the customer information is described,
(id fornamn, efternam.. etc is the column names and the information underneath is the values)
This table is called “kunder”
id fornamn efternamn adress ort postnummer foretag telefon email personNmr husNmr organisationsNmr produkt uppringd prioritet raderad
15 Peter Tressing adress ort 41676 foretag 071234565 email@email.se 123456 4 55658794 Nocria 1 0 0
I called this table kunder_log
id fornamn efternamn adress ort postnummer foretag telefon email personNmr husNmr organisationsNmr produkt uppringd prioritet raderad timestamp type
(the only diffirance is index instead of primary key on the ID and I added the timestamp and type)
(Type the type of the query (insert, delete or update))
Now i want to trigger changes for each row in the table when i do an Update/Insert/Delete query.
But I only want to insert the changes made and not every column in the old table.
Is this possible or do you recomend another approache?
Basically there are two approaches to log all the changes done on main table:
trigger is good option if you want to log all the changes made to tables globally.
write insert into change log tables after every insert, update, delete statement in all stored procedures.
I generally prefer second approach as it is much faster as compared to triggers.
Sample table structure: