1

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) ); 
2

2 Answers 2

1

No, that is not possible.

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

Sign up to request clarification or add additional context in comments.

Comments

1

You can create a VIEW of your table that uses your function to create the value.

http://dev.mysql.com/doc/refman/5.7/en/create-view.html

1 Comment

Link only answers are discouraged. Please add more details to your post, in case the link is ever broken.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.