I would like to have a column's default value be a specified on a per session basis. The below script doesn't work, but describes how I would like to use it. I am currently using MySQL 5.5.28, but can upgrade if necessary.
CREATE TABLE my_tbl (
id INT NOT NULL AUTO_INCREMENT,
data VARCHAR(45),
date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
date_modified TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
created_by INT DEFAULT CUSTOM_USER_ID,
modified_by INT ON UPDATE CUSTOM_USER_ID
PRIMARY KEY (id)
) ENGINE = InnoDB;
-- Will set created_id and modified_id=111
SET @CUSTOM_USER_ID=111;
INSERT INTO my_tbl(data) VALUES('hello');
-- Will set modified_id=222
SET @CUSTOM_USER_ID=222;
UPDATE my_tbl SET data='goodby' WHERE id=1;
-- Will keep modified_id=222
SET @CUSTOM_USER_ID=333;
UPDATE my_tbl SET data='hello again',modified_id=modified_id WHERE id=1;