Create a stored procedure with no parameters
CREATE PROCEDURE Procedure name () procedure Body SELECT VERSION ();
Call the stored procedure
Name of the first call procedure (); (Used with parameters)
Name of the second call procedure (used without parameters)
Create with in the type parameter of the stored procedure (before creating the default delimiter to modify MYSQL is//, after the creation of a good to modify back ; )
The first step DELIMITER A new delimiter such as //
Step Two CREATE PROCEDURE procedure name such as Removeuserbyid (in parameter name such as ID data type such as INT character type such as UNSIGNED)
Step three BEGIN
Fourth Step Deletefrom table name The parameter ID passed in the field in the WHERE data table id=;
Fifth Step END
Sixth step //
Seventh Step DELIMITER the original delimiter;
Remove a program
DELETE PROCEDURE procedure name;
To delete a stored procedure
DROP PROCEDURE process name;
Create with The in and out type parameters of the stored procedure (before creating the default delimiter to modify MYSQL is//, after the creation of a good to modify back ; )
The first step DELIMITER A new delimiter such as //
Step Two CREATE PROCEDURE procedure names such as Removeuserandreturnusernums (in parameter names such as p_id data types such as INT character types such as Unsigned,out parameter names such as Usernums data type such as INT character type such as UNSIGNED)
Step three BEGIN
Fourth Step Deletefrom table name the field in the WHERE data table id= the passed parameter p_id;
Fifth Step Sleectcount ( field such as ID) from table name into parameter name usernums;
Sixth Step END
Seventh Step //
Eighth Step DELIMITER the original delimiter;
call a stored procedure Call process name such as Removeuserandreturnusernums ( to delete such as , the remainder of the total, such as @nums);
Query the remaining total SELECT @nums;
Row_count (); you can query the insertion of the data . Total records deleted and updated
Create with multiple the stored procedure for the out type parameter (before creating the default delimiter to modify MYSQL is//, to be modified back after creation ; )
The first step DELIMITER new delimiter such as // Delete user through age and return information
Step TwoCREATE provedureprocess names such asRemoveuserbyagereturninfos(inchparameter names such asP_agedata types such asSMALLINTcharacter types such asUnsigned,outparameter names such asdeleteusersdata types such asSMALLINTcharacter types such asUnsigned,outparameter names such as usercounts data types such as smallint character types such as unsigned)
Step three BEGIN
Fourth Step Deletefrom table name the field in the WHERE data table age= the passed parameter p_age;
Fifth Step Sleectrow_ count () table name into parameter name deleteusers;
Sixth Step Sleectcount ( field such as ID) from table name into parameter name usercounts;
Seventh Step END
Eighth step //
Nineth Step DELIMITER the original delimiter;
call a stored procedure Call process name such as Removeuserbyagereturninfos ( to delete such as , you want to delete the number of such as @nums, the remaining amount such as @wang);
Query the quantity you want to delete and the amount left after deletion
SELECT such as @nums,@wang;
Query the remaining total SELECT @nums;
There are several fields of data in the query table that you want to query
SELECT COUNT (ID) from table name where you want to query the fields such as age= you want to query the data such as ;
Create a stored procedure for MySQL