mysql-foreign key-view-transaction-index

One, foreign key

The role of foreign keys: to prevent the insertion of invalid information

note:

        Keyword: foreign, only innodb database engine

        The foreign key itself is a kind of constraint, the same as the constraint such as not null.

Second, the view

    A view is a virtual table that can encapsulate the functions of complex SQL statements. So when we create a view, the main job is to create this SQL query. The view is a reference to several basic tables, a virtual table, does not store specific data (the basic table data has changed, the view will also change).

    The benefits of views: convenient operations, especially query operations, reduce complex SQL statements, enhance readability and reusability;

Three, affairs

Definition: Transaction refers to the operation of a series of SQL statements executed as a basic unit of work, either completely executed or not executed at all.

Use of transactions

Four characteristics of transaction ACID

Four, index

The nature of the index : Index is a special file ( the index on the InnoDB data table is a component of the table space) , they contain the location information of all records in the data table.

It should be noted that the primary key is usually indexed by default when the table is built, so using the primary key query when querying data will speed up the query, and creating an index is a very time-consuming operation.

-- 验证索引性能


-- 没有索引
-- 开启时间检测:
set profiling=1;
-- 查找第1万条数据ha-99999
select * from test_index where title="ha-99999";
-- 查看执行时间
show profiles;


-- 有索引
-- 给title字段创建索引
alter table test_index add index(title);
-- 查找第1万条数据ha-99999
select * from test_index where title="ha-99999";
-- 查看执行时间
show profiles;

Guess you like

Origin blog.csdn.net/qq_39197555/article/details/113899116