MySQL Learning notes--indexes and views

Source: Internet
Author: User

Index and manage Indexes

A database object in the schema

Function: Used in the database to speed up the query of the table

Create: Automatically create indexes on primary key and unique key

Reduces disk I/O by quickly locating data by using fast path access methods

Separate from table, but cannot exist independently, must belong to a table

Automatically maintained by the database, indexes on the table are automatically deleted when the table is deleted

The index acts like a directory on a book, and almost no book has no table of contents, so few tables have no index

Indexing: Indexing on fields that are frequently queried, using index to optimize queries (index avoids a full scan of the table)

Principle: When an index is created in a field, the database generates an index page, and the index page saves not only the indexed data, but also the specific physical address of the index in the database.

Note: If the table has very few columns, it is not suitable for indexing. Index fragmentation occurs when the INSERT, delete, and update are executed many times. affect the query speed, we should reorganize the index

Reorganization method: Drop index index_name;

CREATE INDEX index_name on table (column)

# Create indexes manually CREATE INDEX Index_tb_dept_name  on tb_dept (NAME); # Use an index to add an index to a where to improve query efficiency SELECT *  from WHERE NAME='Tom'

Views and Management views

The benefits of a view: You can restrict access to data, make complex queries easier, provide data independence, and provide different explicit

# Create a viewCREATE VIEWEmo_v_10 asSELECTNAME as 'name', sex'Sex', age'Age' fromtb_empWHEREdept_id=2; # Working with viewsSELECT *  fromEmo_v_10

MySQL Learning notes--indexes and views

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.