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