how to set a defaut using function uuid() in mysql? -


i want set uuid value "id" field via function uuid(). , not want use trigger.

create table `test` ( `id` varchar(36) not null default uuid(), `username` varchar(250) null default null, `values` varchar(250) null default null , primary key (`id`) ) engine=innodb; 

the spec quite explicit on this: http://dev.mysql.com/doc/refman/5.0/en/data-type-defaults.html

with 1 exception, default value must constant; cannot function or expression. means, example, cannot set default date column value of function such now() or current_date. exception can specify current_timestamp default timestamp column.

so either use triggers, calculate value beforehand (e.g. in php) or use other database, e.g. oracle might support it.


Comments