SQL Review Guide

An online tool for DBA to generate the SQL review / DDL guideline.

Guideline for Prod
Guideline for Dev

Database Review Guide

Database

Can only drop the database if there's no table in it.

    Column

    Enforce the required columns in each table.

    • Required column names:
      id created_ts updated_ts creator_id updater_id

    Columns cannot have NULL value.

      Schema

      MySQL and TiDB support checking whether the schema change is backward compatible.

        Table

        Require the table to have a primary key.

          Disallow the foreign key in the table.

            Only tables named with specific patterns can be deleted. The requires users to do a rename before dropping the table. The table name must have "_del" suffix by default.

            • Table name format (regex): _del$
            Statement

            Disallow 'SELECT *' statement.

              Require 'WHERE' clause.

                Disallow leading '%' in LIKE, e.g. LIKE foo = '%x' is not allowed.

                  Naming

                  Enforce the table name format and length limit. Default snake_lower_case with 64 characters.

                  • Table name format (regex): ^[a-z]+(_[a-z]+)*$
                  • Length limit (PostgreSQL is not supported): 64

                  Enforce the column name format and length limit. Default snake_lower_case with 64 characters.

                  • Column name format (regex): ^[a-z]+(_[a-z]+)*$
                  • Length limit (PostgreSQL is not supported): 64

                  Enforce the unique key name format and length limit. Default uk_<table_name>_<column_list> with 64 characters.

                  • Unique key name format: ^uk_{{table}}_{{column_list}}$
                  • Length limit (PostgreSQL is not supported): 64

                  Enforce the primary key name format and length limit. Default pk_<table_name>_<column_list>.

                  • Primary key name format: ^pk_{{table}}_{{column_list}}$

                  Enforce the index name format and length limit. Default idx_<table_name>_<column_list> with 64 characters.

                  • Index name format: ^idx_{{table}}_{{column_list}}$
                  • Length limit (PostgreSQL is not supported): 64

                  Enforce the foreign key name format and length limit. Default fk_<referencing_table>_<referencing_column>_<referenced_table>_<referenced_column> with 64 characters.

                  • Foreign key name format: ^fk_{{referencing_table}}_{{referencing_column}}_{{referenced_table}}_{{referenced_column}}$
                  • Length limit (PostgreSQL is not supported): 64
                  Engine

                  Require InnoDB as the storage engine for MySQL.

                    Made by Bytebase at 2022-08-16