如何将列的默认值设置为登录用户?
我正在创建一个“日志记录”表,其中一列应该是登录用户
(the output of "SELECT user();").
这可能吗?
编辑——我试过的:
create trigger logtrigger_test before insert on logging_test for each row set new.changed_by=current_user();
编辑2:描述表
+---------------+-------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| source_table | varchar(50) | NO | | NULL | |
| foreign_id | int(11) | NO | | NULL | |
| field_changed | varchar(30) | NO | | NULL | |
| changed_by | varchar(30) | YES | | NULL | |
| changed_on | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+---------------+-------------+------+-----+-------------------+-----------------------------+
编辑 3:表中的示例条目
+----+---------------+------------+------------------+----------------------+---------------------+
| id | source_table | foreign_id | field_changed | changed_by | changed_on |
+----+---------------+------------+------------------+----------------------+---------------------+
| 0 | phone_numbers | 34 | home_phone | jeff@localhost | 2013-04-10 14:15:13 |
| 1 | contact_info | 24 | first_name | bob@localhost | 2013-04-11 10:18:43 |
| 2 | addresses | 32 | home_address | autoscript@localhost | 2013-04-12 11:10:37 |
| 3 | addresses | 36 | business_address | bob@localhost | 2013-04-12 14:56:17 |
| 4 | addresses | 36 | business_address | jeff@localhost | 2013-04-12 15:25:52 |
+----+---------------+------------+------------------+----------------------+---------------------+