Home > Mobile >  Automatically change the name of column everywhere with the renaming the name of column
Automatically change the name of column everywhere with the renaming the name of column

Time:01-15

I need to change my column name in mysql and I want to automatically update all triggers, procedures, functions where that name is used to new name. How can I do this?

I tried this syntax but it doesn't effect to my funcs, proc etc.

ALTER TABLE t1 CHANGE col1 col2 double;

CodePudding user response:

There is no way of changing a column name and automatically updating all referenced objects.

Your best option is to query objects using information_schema tables and change them.

For example, to query stored procedures and user defined functions that its definition has reference to col1:

SELECT * FROM information_schema.routines WHERE routine_definition LIKE '%col1%'

information_schema reference

  • Related