Section XIII affairs and MySQL indexes, views


The concept of transaction: is a sequence of operations, these operations are either executed or not executed, it is an integral part of a work unit
of the four characteristics of the transaction: the ACID
A: atomicity, a transaction must be regarded as an integral the smallest unit of work, all operations throughout the transaction either submit all succeed, or all fail rollback for a transaction, it is impossible to perform the operation in which only a portion, which is the atomicity of transactions

C: the consistency of the database is always a state transition from a state to another consistent consistency.

I: isolation, generally speaking, a firm changes made prior to the final submission of the transaction are not visible to others

D: persistence, once the transaction commits successfully, it will save changes made to the database permanent

Transaction turned
begin;

sql statement

commit or rollback ends

 

The purpose of the index: improve query efficiency, a reflection of the primary key and foreign key index, but the index will affect the construction of too many updates and inserts the speed,
because he needs to update the same file each index, and the index takes up disk space

set profiling = 1; turn runtime

show index table_name # View index

create index index_name on table_name (field names (length)) # create the index, field names (length) represents the time to create a table field designated varchar (10), if you do not need this length is digital

drop index index_name on table_name # delete indexes

show profiles; # View Execution Time

 

View: return to the view that the implementation of a select statement result set, is a reference to a number of sheets basic table is a virtual table, the specific data is not stored, the basic table data changes, the view will also change

View of the role of
1, improved reusability, equivalent to calling the function, easy to operate, in particular query, reduce the complexity of sql statement, enhance readability,
2, for the reconstruction of the time without modifying the database in python sql statement can not be modified in view of data
3, by filtering data, improve the safety performance, you can display different data for different users
4, make data more clearly


create view view name as select statement; # Create a view

例:
create view v_goods_info as select g.*,c.name as cate_name,b.name as brand_name from tdb_goods as g left join goods_cate as c on g.cate_id=c.id left join brand_name as b on g.brand_id =b.id


show tables; # View View

select * from v_goods_info; # use view

drop view view name; # Delete View

Guess you like

Origin www.cnblogs.com/kogmaw/p/12405840.html