|
DELIMITER $
Drop procedure if exists 'monitor'. 'P _ user _ insertuser' $
# If a stored procedure with the same name exists, delete the stored procedure. monitor is named p_user_Insertuser and stored procedure name (p _ indicates _ operation + indicates)
Create definer = 'liteng' @ '%' PROCEDURE 'P _ user_Insertuser '(
UserName varchar (200) # input parameter userName at the DAL layer (data access layer)
)
BEGIN
Declare id int default 0; # variable id that defines the default value of int
USER_ID into id from monitor_user where USER_Name = userName and USER_State = 1 limit 1;
# In the search table, the USER_Name column is equal to the userName parameter and the USER_State column (user status. When a user is deleted, this value is 0; if the user exists, it is 1, and put the data primary key into the variable id.
If (! Id) then # if there is no data equal to the variable userName, that is, no such user has registered
Insert into monitor_user (USER_Name) VALUES (userName );
# Insert data with userName
Select row_count (); # returns the number of affected rows.
Else
Select-1; # If the data already exists,-1 is returned.
End if;
END $
DELIMITER; |