1. Common SQL Writing specifications
- One field takes a row, and a comma precedes the field;
- Keywords need to be aligned
Select
- Each field is exclusive of one row. The comma is written in front of the field.
- If there are multiple tables after the FROM predicate, each table name is one row, and the comma is written in front of the table name.
- In the Where condition, if there are multiple and/or conditions, each condition takes one row and and/or at the beginning of the line
- The equal sign "=" leaves a space around.
SELECT AS col1 AS col2 ,col3 AS col3 FROM table1 t1 ,table2 t2 WHERE t1.col1 = t2.col1AND t1.col2 = t2.col2;
Insert
- Each field occupies one row, and the comma is written in front of the field name.
- The SQL keyword is aligned to the left, and the fields and values correspond to the keyword indents of 2 or 4.
INSERTINTO table1 ( col1 ,col2 ,col3)VALUES ( 1 ,‘col2‘ ,‘col3‘);
Update/delete
- Each field occupies one row, and a comma is written in front of the field.
- The equal sign "=" leaves a space around.
- If multiple and/or > * are present in the where condition, each condition occupies one row and and/or at the top of the row.
- Keyword update, set, where, and etc right-aligned (Update/delete)
UPDATE table1 SET‘test‘ ‘test‘ WHERE1;
2. Some development recommendations
- Recommendation: Using prepared statement, you can provide performance and avoid SQL injection.
- Recommendation: In SQL statements, the in contains values should not be too large.
- Recommendation: UPDATE, DELETE statements do not use limit.
- Recommendation: The appropriate type must be used in the where condition to avoid the implicit type conversion of MySQL.
Database Development Specification