Database Development Specification

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.