Database refactoring

A database refactoring is a simple change to a database schema that improves its design while retaining both its behavioral and informational semantics. Database refactoring does not change the way data is interpreted or used and does not fix bugs or add new functionality. Every refactoring to a database leaves the system in a working state, thus not causing maintenance lags, provided the meaningful data exists in the production environment.

A database refactoring is conceptually more difficult than a code refactoring; code refactorings only need to maintain behavioral semantics while database refactorings also must maintain informational semantics.

You refactor a database schema for one of several reasons:

  1. To develop the schema in an evolutionary manner in parallel with the evolutionary design of the rest of your system.
  2. To fix design problems with an existing legacy database schema. Database refactorings are often motivated by the desire for database normalization of an existing production database, typically to "clean up" the design of the database.
  3. To implement what would be a large (and potentially risk) change as a series of small, low-risk changes.

Database refactorings

Examples of database refactoring:

  • Splitting an aggregate table into two different tables in the process of .
  • Renaming an existing column to make its purpose clearer.
  • Combining two columns into a single one because they were being used for the same purpose.
  • Splitting an existing column into two or more columns because the original column was being used for several purposes (so you have one column per purpose).
  • Applying a common data format to a column so as to increase the consistency of the data.
  • Common code refactorings (Rename Method, Introduce Variable, Rename Variable, and so on) to database code such as stored procedures and triggers.
  • Introducing a view to implement a common access path to data.

Process of database refactoring

The process of database refactoring is the act of applying database refactorings to evolve an existing database schema (database refactoring is a core practice of evolutionary database design). There are three considerations that need to be taken into account:

  1. How to implement a single refactoring
  2. How to track/share database refactorings across your organization
  3. How to apply a series of database refactorings to a database

See also


    This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.