Skip to content
Advertisement

How can i define variable for default values in MariaDB structure?

I need to change a lot default values of the DB structure for new entries in MULTIPLE tables to have this new default value in DB I tried to use something like this:

JavaScript

But the SET prefix does not fork for alter table command. Is there any way how to do this to use pre-defined value so I can only change it once in SET or simillar definition? I tried to search documentation but maybe just missed it?

Advertisement

Answer

You can use dynamic query like this:

JavaScript

Sample Data:

JavaScript

Result:

JavaScript

So the first item had 10 as default value and second item has been changed to 20. You see that it works.


For multiple values, you cannot put multiple queries inside one statement: Doc

The text must represent a single statement, not multiple statements.

So you can create another procedure for convenience:

JavaScript

Use it like this:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement