Refactoring Usage

This topic describes examples of situations, where users can benefit the most form refactoring.

Renaming columns referenced by other columns using foreign keys

When renaming a column, it is necessary to make sure that all references using foreign keys are working. When simply renaming the column, you will have to find all foreign keys, delete them, rename the column and recreate the keys. When renaming using refactoring, the application will find all foreign keys and apply the new column name in all database.

Renaming columns used in creating views

It often happens that the column you need to rename is used in views. In case you just rename the column, you’ll get an error when data is selected for the view. To avoid it, you will have to edit all views that use the renamed column after you actually rename it. Refactoring tool in dbForge Studio will edit all views on its own after you rename the column.

Renaming objects with code

If you rename an object with code, for example, a stored routine and make a mistake in the code, the procedure or function will be lost and you will have to recreate it from memory.

dbForge Studio for MySQL refactoring tool uses a special algorithm that changes such scenario:

  1. A temporary stored routine is created. It contains the code of the procedure before renaming.
  2. All objects that use this routine are deleted.
  3. All objects that use this stored routine are recreated, but the routine is renamed.
  4. The routine with new name and new code is created.
  5. The temporary stored routine is deleted.

In case the fifth step fails, the script execution stops and the original code can be restored from the temporary object.