Skip to main content

6. Character Set / Collation

Disallow Character Set Specification on Table Definition

** Name:** CharsetOnTableDisallowed

Rule Description: Prohibit specifying character sets when defining tables to avoid data issues caused by inconsistent character sets.

Warning Level: Warning

Review Object: CREATE TABLE

Trigger Condition: Character set is specified when creating a table.

Configurable: No

Supported Database Types: All (ALL)

Tables Should Use Specified Character Set

Code: SpecificCharSet4TableRequired

Rule Description: Require tables to use a specified character set, such as UTF-8, to ensure data consistency and internationalization support.

Warning Level: Warning

Review Object: CREATE TABLE

Trigger Condition: Table does not use the specified character set.

Configurable: Yes

Example: The expression can be configured as utf8mb4(mysql) utf8(pg), indicating that MySQL and PostgreSQL tables should use UTF-8 encoding.

Supported Database Types: MySQL, PostgreSQL

Tables Should Use Specified Collation

Code: SpecificCollation4TableRequired

Rule Description: Require tables to use a specified collation to ensure that data comparison and sorting behavior meets expectations.

Warning Level: Warning

Review Object: CREATE TABLE

Trigger Condition: Table does not use the specified collation.

Configurable: Yes

Example: The expression can be configured as utf8mb4_0900_ai_ci, indicating that the table should use UTF-8 encoding and case-insensitive collation.

Supported Database Types: MySQL

Mismatch Between Table and Database Character Sets

Code: CharsetsOnTable&DatabaseMismatch

Rule Description: Require the table's character set to be consistent with the database's character set to avoid data consistency issues.

Warning Level: Warning

Review Object: CREATE TABLE

Trigger Condition: The table's character set is inconsistent with the database's character set.

Configurable: No

Supported Database Types: All (ALL)

Disallow Specifying Column Character Set

Code: CharsetOnColumnDisallowed

Rule Description: Prohibit specifying character sets for individual columns to avoid data issues caused by inconsistent character sets.

Warning Level: Warning

Review Object: CREATE TABLE, ALTER TABLE MODIFY COLUMN

Trigger Condition: A character set is specified for an individual column.

Configurable: No

Supported Database Types: All (ALL)

Mismatch Between Column and Table Character Sets

Code: CharsetsOnColumn&TableMismatch

Rule Description: Require the column's character set to be consistent with the table's character set to ensure data consistency.

Warning Level: Warning

Review Object: CREATE TABLE, ALTER TABLE MODIFY COLUMN

Trigger Condition: The column's character set is inconsistent with the table's character set.

Configurable: No

Supported Database Types: All (ALL)

Database Character Set Must Be Specified When Creating Database

Code: Charset4DatabaseRequired

Rule Description: Require specifying a character set when creating a database to ensure data consistency and compatibility.

Warning Level: Warning

Review Object: CREATE DATABASE

Trigger Condition: Character set is not specified when creating a database.

Configurable: No

Supported Database Types: All (ALL)

Database Should Specify Default Collation

Code: Collation4DatabaseRequired

Rule Description: Require specifying a default collation when creating a database to ensure that data comparison and sorting behavior meets expectations.

Warning Level: Warning

Review Object: CREATE DATABASE

Trigger Condition: Default collation is not specified when creating a database.

Configurable: No

Supported Database Types: All (ALL)

Specified Character Set Must Be Used When Creating Database or Schema

Code: SpecificCharset4DatabaseRequired

Rule Description: Require using a specified character set when creating a database or schema to ensure data consistency and compatibility.

Warning Level: Warning

Review Object: CREATE DATABASE, CREATE SCHEMA

Trigger Condition: The specified character set is not used when creating a database or schema.

Configurable: Yes

Example: The expression can be configured as utf8mb4, indicating that UTF-8 encoding should be used when creating a database or schema.

Supported Database Types: All (ALL)

Use Specified Collation When Creating Database or Schema

Code: SpecificCollation4DatabaseRequired

Rule Description: Require using a specified collation when creating a database or schema to ensure that data comparison and sorting behavior meets expectations.

Warning Level: Critical

Review Object: CREATE DATABASE, CREATE SCHEMA

Trigger Condition: The specified collation is not used when creating a database or schema.

Configurable: Yes

Example: The expression can be configured as utf8mb4_0900_ai_ci, indicating that UTF-8 encoding and case-insensitive collation should be used when creating a database or schema.

Supported Database Types: All (ALL)