[Reserved] database based learning with the mind

Source: https://www.liaoxuefeng.com/wiki/1177760294764384

  1. Without using any field related to the service as a primary key
  2.  

     Without necessary, we try not to use the primary key, because it brings to the table a rise in complexity

  3. As the foreign key constraint will reduce the performance of the database, the majority of Internet applications for the pursuit of speed, does not set the foreign key constraint, but only by the application itself to ensure the correctness of the logic. In this case, class_idjust a regular column, but it played a key role outside of it.
  4. Many relationship is actually implemented by two-to-many relationship, that is, through an intermediate table, associated with two-many relationship to-many relationship is formed:
  5. There are some applications, a large table will split into two tables one object is to separate and often do not always read the read field, in order to obtain higher performance. For example, to split a large user table for the user basic information table user_infoand user detailed information table user_profiles, most of the time, only need to query the user_infotable, you do not need to query the user_profilestable, so that you can improve query speed.
  6. The index is a data structure in the relational database for pre-sorting a plurality of values ​​of a row or column. By using the index, you can let the database system does not have to scan the entire table, but directly to locate records meet the criteria, thus greatly speeding up the query speed.
  7. Efficiency index depends on whether the hash value of the index column that the column value if the more different from each other, so the higher the efficiency index. Conversely, if there is a recording of a large number of columns of the same value, such as gendercolumns, about half of the recorded values M, the other half is F, therefore, create an index on that column does not make sense. You can create multiple indexes on a table. Advantage of the index is to improve query efficiency, the disadvantage is in insert, update and delete records time, you need to modify the index, so the more the index, insert, update, and delete records slower pace. For primary key, its relational database will automatically create a primary key index. Efficient use of the primary key index is the highest since the primary key will be the only absolute guarantee.
  8.  Without FROMclause SELECTstatement has a useful application, is used to determine the current connection to the database is valid. Many detection tool performs a SELECT 1;test database connection.

  9. OFFSETMore than the maximum number of queries and does not complain, but to get an empty result set.

    In MySQL, LIMIT 15 OFFSET 30it can also be abbreviated as LIMIT 30, 15.

    Use LIMIT <M> OFFSET <N>when paging, as Nmore and more, the query efficiency will be lower and lower.

  10. Aggregate query: SELECT COUNT (*) FROM students; packet aggregation: SELECT COUNT (*) num FROM students GROUP BY class_id;
  11.  

     

  12.  

     

     

     

  13.  

     

     

     

  14. The multi-function statements as a whole to operate, is called a database transaction. Ensures that all database transactions can operate within the scope of a transaction can all succeed or all fail. If the transaction fails, then the effect would be without the implementation of these SQL, as there will be no changes to the database data.
  15.  

     

  16. Dirty read (Dirty read)
  17. Phantom read:

     

     

  18.  

     

 

Guess you like

Origin www.cnblogs.com/jiading/p/11454834.html