I want to capture when a user logs in/out.
create table user_history ( user_id SMALLINT NOT NULL, logged_in TIMESTAMP, logged_out TIMESTAMP, FOREIGN KEY ( user_id ) REFERENCES users (user_id) );
When a user loggs in I
INSERT INTO user_history (user_id, logged_in) VALUES ( 1, now());
But what would I run when he logs out?
UPDATE user_history SET logged_out = now()) WHERE ?
Do I need to set a PK in order for the WHERE clause to work?