Database design and usage standards based on Alibaba's java development manual

In order to unify the database design and use standards, refer to Alibaba's java development manual, and extract several specifications:

1. Table building protocol:

1. Table names and field names must use lowercase letters or numbers. It is forbidden to start with numbers, and only numbers between two underscores are prohibited.
正例:getter_admin task_config level3_name
Counterexample: get special Admin, taskConfig, level_3_name

2. When the table is named, add a business prefix, such as the permission service related table, which starts with priv_. It is convenient for subsequent demolition operations.

3. The length of table name and field name should not exceed 30

4. Corresponding description information must be added when building tables and fields.

5. The primary key index name is pk_table name_field name, the unique index name is uk_table name_field name, and the common index name is idx_table name_field name.
Description: pk_ is primary key; uk_ is unique key; idx_ is short for index.

6. The table must have 3 fields, id, create_time, update_time.
Description: id must be the primary key, create_time indicates the creation time, and update_time indicates the update time. The types of create_time and update_time must be date_time, gmt format.

  

Second, the index specification:

1. If there are more than three tables, the use of join is prohibited. The data types of the fields that need to be joined must be absolutely consistent. When querying multi-table associations, ensure that the associated fields need to have indexes.
Note: Even if you say table join, you should pay attention to table index and sql performance.

2. Left-blur or full-blur is strictly prohibited in page search. If it is really necessary, go to the search engine to solve it.
Description: The index file has the leftmost prefix matching feature of B-Tree. If the value on the left is not determined, this index cannot be used.

  

Three, sql statement

1. The use of select * is strictly prohibited.

2. Use ISNULL() to determine whether it is a NULL value.
Note: Symbols such as = <> cannot be used. Because select null=null returns null, and select null<>null returns null

3. The use of stored procedures is prohibited. Stored procedures are difficult to debug and extend, and have no portability.

4. Foreign keys and cascades cannot be used. All foreign key concepts need to be solved at the application level.
Note: (concept explanation) The student_id in the student table is the primary key, then the student_id in the grade table is the foreign key.
If you update the student_id in the student table and trigger the update of the student_id in the grade table at the same time, it is a cascading update.
Foreign keys and cascading are more suitable for single-machine low concurrency, but not for distributed, high-concurrency clusters.
Cascading updates are more blocking, and there is a risk of data update storms.
Foreign keys affect the insertion speed of the database.

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324925810&siteId=291194637