mysql view / Trigger / function / stored procedure

A view

Role: shorthand codes, and the role of temporary tables almost

1 Create
 the Create  View view name as SQL statements
 2 modification.
 The ALTER  View view name as the new SQL statement
 3 deleted.
 Drop  View view name 
Note: Views are virtual, SQL statements, produces a temporary table

Second, the flip-flop

Action: do additions and deletions to the operation of a particular table, the trigger may be used to define the connection behavior

DELIMITER // 
the Create tigger name of the before INSERT  ON tb1 for the each Row
 the begin 
INSERT  INTO TB2 (column) values (NEW, sname);
 End  // 
DELIMITER; 

essence: create a trigger, when tb1 operation, tb2 will accordingly operation 
Note: NEW OLD 
        the before INSERT         
        the After INSERT 
        the before Update 
        the After Update 
        the before the Delete 
        the After the Delete     
INSERT with NEW delete with OLD update with NEW and OLD

Third, function

Category: built-in functions, custom functions

1 . Calling function 
 select function name ();
 2 . Built-in function
 select CURDATE ();
 select the DATE_FORMAT (time format);
 3 . Custom function 
DELIMITER // 
Create  function FUNC ( 
    A int , 
    B int )
 Returns  int 
the begin 
DECLARE NUM int defaukt 0 ;
 SET NUM = A + B;
 return (NMU);
 End  // 
DELIMITER; 
SELECT FUNC ( . 5 ,3 ) 
Note: The function can not be used in SQL statements

Fourth, the flip-flop

https://www.cnblogs.com/wupeiqi/articles/5713323.html

 

Guess you like

Origin www.cnblogs.com/wt7018/p/11110751.html