user3841111 user3841111 - 19 days ago 5
MySQL Question

MySQL function in column default value

Is it possible to use function in column default value?

I want to do something like that:

CREATE TABLE FOO
(
col1 varchar(100),
col2 varchar(1) NOT NULL DEFAULT SUBSTRING(col1,1,1)
);

Answer

No, that is not possible.

Only static values are allowed and times values like current_timestamp or current_date.

Comments