How can I create an auto generated column that always has its default value in MySQL?

I want to create a MySQL column that always uses its default value and won't allow the user to insert values in it.

It's a creation_date column and I've set its default value to now(), but the user can insert any date value in this column if he wants to. The now() is only used if the user don't provide any values for that column.

I can imagine a few ways to accomplish my goal using triggers, but, is this the right way?

Isn't there a "protected" flag to set on the column or something like that?

Upvotes: 0

Views: 937

Answers (1)

chaos
chaos

Reputation: 124267

There is no "protected" column concept, no. You would need to use triggers.

Upvotes: 1

Related Questions