MySQL build index, trigger

Source: Internet
Author: User

To create an index:
ALTER table < table name > ADD INDEX (< field >);
>alter TABLE ' table_name ' ADD PRIMARY KEY (' column '); Add primary key (primary key index)
>alter TABLE ' table_name ' Add unique (' column '); add unique (unique index)
>alter TABLE ' table_name ' Add index index_name (' column ') add index (normal index)
>alter TABLE ' table_name ' Add fulltext (' column ') added fulltext (full-text index)
>alter TABLE ' table_name ' Add index index_name (' Column1 ', ' column2 ', ' column3 ') Add multi-column index
>describe tbale_name; View table structure information
>drop index index_name on Table_name;drop deleting indexes
>alter table table_name DROP INDEX index_name;alter DROP Delete indexes
>alter table table_name Drop primary Key;alter Delete index

To create a trigger:
CREATE TRIGGER trigger_name trigger_time trigger_event on tb_name for each ROW trigger_stmt;
Trigger_name: Name of the trigger
Tirgger_time: Trigger time for before or after
Trigger_event: Trigger event for INSERT (Insert,load data,replace), DELETE (delete,replace), or update
Tb_name: Indicates the name of the table that created the trigger
TRIGGER_STMT: The program body of a trigger, which can be an SQL statement or multiple statements contained by BEGIN and end
The Before and after parameters specify the time to trigger execution, either before or after the event
The for every row indicates that the action on any one record satisfies the triggering event and triggers the trigger
MySQL can create the following six types of triggers:
Before Insert,before Delete,before UPDATE
After Insert,after Delete,after UPDATE

Drop trigger trigger_name; #删除触发器
Show triggers; #查询触发器
To create a trigger with more than one execution statement
CREATE TRIGGER Trigger Name before| After Trigger event
On table name for each ROW
BEGIN
Executes a list of statements to; Separated
END

At the begin ... The end statement defines the variable, but only at the begin ... End internal use:
DECLARE var_name Var_type [DEFAULT value] Character set UTF8; #定义变量, you can specify a default value
SET var_name = value; #给变量赋值

Tips:mysql special symbol; There is a conflict in the trigger, using a separate execution before and after the trigger DELIMITER | | (the end symbol is defined as | |) and delimiter;(to restore the ending symbol to;).

MySQL build index, trigger

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.