views and things

Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.

views and things

The statement of view creation, deletion and modification in MySQL is similar to the syntax of table creation, deletion and modification.

The syntax for creating a view is:

CREATE VIEW view name AS query SQL statement

as follows:

CREATE VIEW student_view AS SELECT s.sname 'student name',s.address 'contact address',s.phone 'phone number',c.cname 'class name' FROM student s INNER JOIN cls c ON s.cid=c. cid ORDER BY s.sid DESC

Note: If the SQL statement in the view involves multiple tables, you cannot DELETE UPDATE INSERT for the view.

The delete view syntax is:

DROP VIEW view name

Modify the view syntax to:

ALTER VIEW view name AS query sql statement

MySQL transactions can make our data operations in the database more secure. Example questions are as follows:

image

The transaction end methods include commit commit and rollback rollback. Commit commit is to permanently write the operations in the transaction to the database, and rollback rollback cancels all operations of this transaction.

The automatic transaction setting statement is SET autocommit=1, and each statement is an automatic transaction by default.

The manual transaction setting statement is SET autocommit=0, we need to enter start transaction to manually start a transaction.

After the addition, deletion and modification statement in the manual transaction is executed, an exclusive lock is automatically added to the statement, and no other transactions are allowed to access it. Only when the transaction is ended, other transactions can access it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326450301&siteId=291194637