Given there are no answers yet, here are my 2 cents:
- For Insert, I would use a DateTime field with default value GETDATE()
- For Update, I would use also a DateTime field modified by trigger each time there is an update.
- For Delete, the record won't be available, so you can't query it.
I thought about using Timestamps for avoinding triggers, but you can't convert Timestamp to Datetime.
EDIT:
Or maybe you can use a "metatable" where in the triggers you will save the change dates
CREATE TABLE metatable (
table_name VARCHAR(40) NOT NULL PRIMARY KEY,
last_insert DATETIME NOT NULL,
last_update DATETIME NOT NULL,
last_delete DATETIME NOT NULL
)
INSERT metatable VALUES ('table1', GETDATE(), GETDATE(), GETDATE())
CREATE TRIGGER trg_table1_ins ON table1 FOR INSERT AS BEGIN
UPDATE metatable SET last_insert = GETDATE() WHERE table_name = 'table1'
END
CREATE TRIGGER trg_table1_upd ON table1 FOR UPDATE AS BEGIN
UPDATE metatable SET last_update = GETDATE() WHERE table_name = 'table1'
END
CREATE TRIGGER trg_table1_del ON table1 FOR DELETE AS BEGIN
UPDATE metatable SET last_delete = GETDATE() WHERE table_name = 'table1'
END
I hope it be useful