Brief triggers, functions, views, stored procedures?

Trigger: Trigger is a special storage process, it is a code block in MySQL insert, update, delete, when executed automatically.

     create trigger trigger_name

   after/before insert /update/delete on 表名

   for each row

   begin

   :( sql statement triggered a sentence or sentences)

   end

 Function: MySQL provides many built-in functions, can also customize function (the programmer needs to implement logic processing sql)

   Create a custom function syntax:

       Created: CREATE FUNCTION function name (parameter list)  

          RETURNS type of the function return value thereof

   Modify: ALTER FUNCTION function name [characteristic ...]

   Delete: DROP FUNCTION [IF EXISTS] function name

   Call: SELECT function name (parameter list)

  

   View: A view is a virtual table is formed by the query result, the projection is a calculation table obtained by some

      create view view_name as select 语句

   Stored procedures: a piece of code to encapsulate, when you want to execute this piece of code, can be achieved (after the first compilation called again need to compile again, a high efficiency ratio sql statement execution) by calling the stored procedure

   create procedure stored procedure name (parameter, parameter, ...)

   begin

   // Code

   end

 

1, views

The view is just a logical object is a virtual table , it is not a physical object , because the view does not account for the physical storage space, tables in the view being queried called base table view, most of the select statement can be used in create a view ( it plainly, is a kind of virtual table view, like an electronic photo )

Advantages : the user data set, the complexity of mask data, and to simplify the management of rights to other applications output reorganize data

2, flip-flop

(1) A trigger is a particular stored procedure, which is a code block in MySQL insert, update, delete, when executed automatically.

(2) the trigger must be defined on a particular table.

(3) automatically, it can not be called directly,

( To put it plainly, the flip-flop is actually a God, he would stay in his temples, when the suffering people, such as insert, update, delete, he will be fighting the devil by some of the prayer ritual, automatic! )

3, function

It is almost like php js function or: need to define, and then call (use).

Just provisions of this function, we must return data - to have a return value

4, stored procedures

Stored procedure (Procedure), the concept is similar to the function, is to encapsulate a piece of code, to be executed when this piece of code may be implemented by invoking the stored procedure. In the statement inside the package body, can be the same if / else, case, while the control structure and the like, can be programmed sql, view an existing stored procedure.

Guess you like

Origin www.cnblogs.com/Rivend/p/12099970.html