ALTER TABLE tablename ADD COLUMN ts timestamp;
ALTER TABLE tablename ALTER COLUMN ts SET DEFAULT CURRENT_TIMESTAMP;
This will add a column which will get the time of the transaction on every insert automatically.
You should use table and column names appropriate to your situation of course, also, if you are making the table you can pop the default in when you define the column like so.
CREATE TABLE tablename ( ..., ts timestamp DEFAULT CURRENT_TIMESTAMP,
+... );
The insert needs to be INSERT INTO tablename ( col1, col2 ) VALUES ( ?, ? ); rather than one which does INSERT INTO tablename VALUES ( ?, ? ); otherwise you will have a column count mismatch.
|