mysql three basic summary

INSERT Statement The basic syntax
INSERT INTO <table> (column, row, column) VALUES (value, value, value)
in principle, perform an INSERT INTO statement to insert a row
but it is also just the principle, in fact, many RDBMS support once insert multiple rows of data, a plurality of rows separated by a comma is inserted between each bracket!
When the table is full row INSERT, you can omit the column list after the table name, this time VALUES clause default value assigned to each row from left to right order!
When the INSERT statement want to give a column giving NULL values, you can write directly on the list of values inside the VALUES clause of NULL, NULL, but you want to insert the words can not be set constraint NOT NULL!
We can insert the default value (initial value) to the table, dEFAULT constraint can be set to create a table cREATE tABLE statement to set the default value!
Insert the default values are explicitly insert, there is an implicit insert! Explicit value is inserted which forms, directly fill the DEFAULT, so RFBMS will be paid automatically default values corresponding to columns when a record!
Implicit inserted directly omitted his columns as well as value, so that he will automatically default to a 0,
the column name is omitted in the INSERT statement, it will automatically set the default value for the column (will be set up if there is no default value as NULL) so if the omission is set NOT NULL column constraint, INSERT statement will throw an error!

Copy the data from other tables you can use INSERT .... SELECT, can be used when the need for data backup!
Syntax: INSTART INTO <table> (column name) SELECT <column name> FROM <table>
the SELECT statement INSERT statement, you can use any SQL syntax WHERE clause or GROUP BY clause, etc. (but using ORDER BY child sentence and will not have any effect)!

DROP TABLE statement, and DELETE statements
1.DROP TABLE statement table can be completely removed
2.DELETE statement will leave the table (container), and delete all the data in the table!
DELETE basic syntax
retain data table, delete all the data, not the DELETE statement deletes the object tables or columns, but the records (rows)
DELETE the FROM <table>
Of course we can also use WHERE delete the specified conditions, this type of search is called DELETE syntax
DELETE FROM <table> WHERE <condition>
Note! DELETE not use GROUP BY, HAVING, and ORDER BY clause three, the WHERE clause can only be used as the data extracted for changing the form GROUP BY, HAVING, and are selected from the table data,
and is used to specify the acquisition ORDER BY the results show that the order of the data, therefore, delete data in the table when they can not play any role!
Using standard SQL delete data from the table only DELETE statement, however, many database products, there is another TRUNCATE (discarded) statement! And DELETE it different is that it can only delete all the data in the table, and not through
the WHERE clause specifies the conditions to remove! Probably because it can not delete specific control objects, so processing speed is much faster than DELETE!

Use UPDATE statement may change (update) the data table, the data updating section rows may be used to specify conditions WHERE update target,
designated by the update target UPDATE statement WHERE clause becomes a searched UPDATE statement! UPDATE updates the value of a column is NULL,
can be updated at the same time a plurality of columns, as long as the SET clause UPDATE statement, column A comma separated using a plurality of update target!
UPDATE statement UPDATE <table name> the SET <column name> = <expression (expression also updated data)>;
UPDATE statement specified conditions UPDATE <table name> the SET <column name> = <expression> the WHERE < conditions>;

Use UPDATE columns can also be updated to NULL (commonly known as NULL empty), copy the value of the right of expression to write directly to NULL on it! (It can only be used to set the NOT NULL constraint in!)


A transaction is a collection of the update process needs to be executed in a single processing unit, through the use of a transaction, you can update the data in the database of submission and cancellation process to manage!
Termination instruction transactions include COMMIT (commit processing) and ROLLBACK (cancel treatment) in two!
DBMS transaction has ACID properties, atomicity (Atomicity), consistency (Consistency), isolation (Isolation) and persistent (Durability Rev) four kinds of characteristic
COMMIT-- committed transaction
COMMIT instruction is submitted to the end of all of the update processing transactions comprising ! Equivalent coverage, once submitted can not be restored to the state before the transaction began!
We do not know the start time of the transaction, but must be confirmed at the end of the transaction carefully!
ROLLBACK-- cancel processing
ROLLBACK command is canceled as a result of all transactions included in the update process, the equivalent document processing discard, once rolled back, the database will be restored to the state before the transaction is usually begin to roll back that will not cause as submitted massive loss!

In fact, the beginning of the transaction and there is no standard instructions! Almost all of the transactions database products are not need start command, because in most cases, the establishment of a transaction when the database has already quietly begun!
It does not require the user to re-issue clear instructions to start! Like the case without using the instructions quietly begin a transaction, each SQL statement is a transaction (auto commit mode)
until the user performs COMMIT or ROLLBACK so far counted as one transaction!
START TRANSACTION; start (MySQL)
ROLLBACK; roll back the transaction
COMMIT; commit the transaction

ACID properties
of atomicity refers to the end of a transaction, updating it contains either all executed or not executed at all!
Consistency refers to the processing transactions included in the database to meet the constraints set in advance! Consistency is also called integrity!
Isolation refers to ensure no interference between different transactions feature that ensures that no nested transactions between each other, in addition, to make changes in a transaction before the end of the transaction,
other terms of the transaction It is not visible!
Persistence also become durability, referring to the transaction (either commit or roll back) after the end, DBMS can ensure that the data can change the state point of time will be saved properties, even if a system failure cause data loss, the database will be able to recovery with some means!
If you can not guarantee durability, even at normally submitted to the end of the transaction, once the system failure, can lead to loss of data, everything needs to start all over again, ensure the persistence methods differ according to different implementations, the most common is to saving the transaction records to a hard disk storage medium
(referred to as the execution log recording!, when a failure occurs, can be restored to the state before failure occurs through the log!)

 

Guess you like

Origin www.cnblogs.com/yeapy/p/11580036.html