snippetsqlMinor
How can I get MySQL to use the value returned by a function as a default?
Viewed 0 times
canthereturnedfunctionvaluemysqlgetdefaulthowuse
Problem
I have a pre-existing table that has a column to that can hold a UUID.
I'd like to be able to define a default such that new rows coming in (from legacy systems) will still get a UUID defined, via the
I'd like to be able to define a default such that new rows coming in (from legacy systems) will still get a UUID defined, via the
UUID() function -- is it possible to configure the default of a column to be a value returned by UUID (in a similar manner to how you can for the UNIX_TIMESTAMP() in phpMyAdmin)Solution
Using a trigger
You can't use functions as defaults in MySQL, except for CURRENT_TIMESTAMP for TIMESTAMP columns
You can't use functions as defaults in MySQL, except for CURRENT_TIMESTAMP for TIMESTAMP columns
Context
StackExchange Database Administrators Q#7893, answer score: 7
Revisions (0)
No revisions yet.