Database------index, view

index index

In order to improve query efficiency,
the index is based on the field and is added

type of index

  • Unique index: primary key constraints, unique constraints are unique indexes

  • Ordinary index: can be added to any required field

  • Composite index: combine multiple fields to build an index

Will SQL use a composite index, using a最左原则

What kind of fields are suitable for adding indexes

    1. The primary key comes with a unique index
    1. Unique keys are suitable for adding indexes
    1. Foreign keys are suitable for adding indexes (adding foreign key constraints will bring their own indexes)
    1. Fields that often appear in where conditions
    1. The value repetition rate in the field is not high, suitable for adding indexes
    1. Fields that are often used for grouping are suitable for adding indexes

add index

create [unique] index <indexName> on <tableName>(columnName, ...)

alter table <tableName> add index <indexName>(columnName, ...) ;

delete index

drop index <indexName> on <tableName> ;

alter table <tableName> drop index <indexName> ;

ViewView

View View is a mapping of a real table, a virtual table, and an SQL command.
The view does not store data, but stores SQL query commands.

The role of the view

  1. Hide the real table to ensure data security
  2. simplified query

create view


create view <viewName> as select ... ;

delete view

drop view <viewName> ;

Guess you like

Origin blog.csdn.net/weixin_52953038/article/details/126714328