Recently, I was preparing for the re-examination of the postgraduate entrance examination. Spend a few days to quickly review SQL.
Recommend a quick learning website: http://xuesql.cn/
Online programming exercises are available above. The analysis is only 8.8, and a copy of "SQL must be asked" 》
(Please pay the advertising fee, ah! Hey!!
The concept of transaction: A transaction is a series of operations performed by a single logical unit, either all succeed or all fail . A transaction can be a SQL or a group of SQL
transactions. Four characteristics:
ACID is atomicity and consistency. , Isolation, durability
Concurrency Consistency Problem
1. Lost modification
Example: thread1: write a=1; thread2: write a=2; overwrite the previous modification
2.
Example of reading dirty data : thread1: read a=1; thread1: modify a=2 ;Thread2: read a=2
3. Non-repeatable read
Example: thread1: read a=1; thread2: modify a; thread1 read a=2;
4. Phantom reading
example: thread1: count(List)=100; thread2: List .add("1"); thread1: count(List)=101
3 and 4 have similarities, 3 is to modify data midway, 4 is to insert data midway,
refer to the very vivid blog
https://my.oschina.net/ bigdataer/blog/1976010
The difference between non-repeatable reading and phantom reading :
non-repeatable reading means that B modifies A's data. At this time, A does not know that the
phantom reading is that B is a bystander reader, and A modifies his own data. At this time, B without the knowledge of
MVCC multi version concurrency control multi-version concurrency control
can be achieved submit read and re-read these two isolation levels
SQL basic board: the
most classic six lines
SELECT column_1,column_2... AS column_new_name1,column_new_name2
FROM TABLE1
INNER JOIN/LEFT JOIN/RIGHT JOIN/FULL JOIN TABLE2 ON blabla
WHERE TABLE1.column_x=TABLE2.column_y
ORDER BY... ASC/DESC
LIMIT ... OFFSET ...
Wildcard:
LIKE: In order to use wildcards in the search sentence, you must use LIKE
%: match 0~n characters
_: match 1 character
External connection:
left connection, right connection, internal connection, full connection: It is easy to understand, use the Venn diagram to see the AB relationship
Three paradigms: the
first paradigm 1NF: each column of the data table is an indivisible atomic data item. The
second paradigm 2NF: each column must be related to the primary key, not part of the primary key. The
third paradigm 3NF: ensure each column of the data table Directly related to the primary key, not indirectly related
Four isolation levels
1. Uncommitted read: allow other transactions to read the data before the transaction is not committed.
read uncommited may appear dirty read
2. Commit read: the modification made by one transaction is invisible to other transactions before commit the
read commit to solve the dirty read, possible non-repeatable read
3. repeatable read: the same transaction in the result of reading the same data multiple times is the same as
to solve the non-repeatable read may occur phantom read
MySQL's default isolation: Note The level is Repeatable read
4. Serializable: the execution of the transaction one by one will continue to execute the next transaction after the transaction is submitted. The
transaction is executed sequentially to avoid phantom reads
Finally, write about query execution order :
a large frame is SELECT... FROM... WHERE...
followed by two filters GROUP BY... HAVING...
and finally sorting and searching the index rangeORDER BY ...LIMIT
SELECT DISTINCT column, AGG_FUNC(column_or_expression), …
FROM mytable
JOIN another_table
ON mytable.column = another_table.column
WHERE constraint_expression
GROUP BY column
HAVING constraint_expression
ORDER BY column ASC/DESC
LIMIT count OFFSET COUNT;
the difference between where and having the
back where the data table with which is present in the field
having been screened from a field re-screened
SELECT selects multiple columns, add a comma (,) between the columns.
Multiple SQL statements must be separated by a semicolon (;).
Use the DISTINCT keyword, put it in front of the column, and return the column with a unique value (filter duplicate values)
LIMIT a, b understanding: skip a line, start reading from a + 1 line, take the data of b line
limit a offset b understanding: separate b lines, start reading a line data from b + 1