Help Databases and objects

Stored procedures

A stored procedure is a block of SQL kept on the server and run with CALL. bonSQL writes procedures as SQL: it opens an editor tab with a statement for you to complete or change, and you run it like any other query.

The commands are under Others > Stored Procedures, and on the menu you get by right-clicking a database’s Stored Procs folder or a procedure in the Object Browser. With that folder or a procedure selected, F4, F6 and Del act on procedures.

A stored procedure opened with Alter Stored Procedure in its editor tab

Creating a procedure

  1. Select the database, then choose Others > Stored Procedures > Create Stored Procedure… (F4) or Database > Create > Stored Procedure….

  2. Type a name in Enter new procedure name and click Create. If a procedure of that name already exists in the database, bonSQL says so.

  3. A new editor tab opens with a skeleton:

    DELIMITER $$
    
    CREATE
        /*[DEFINER = { user | CURRENT_USER }]*/
        PROCEDURE `shop`.`close_month`()
        /*LANGUAGE SQL
        | [NOT] DETERMINISTIC
        | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
        | SQL SECURITY { DEFINER | INVOKER }
        | COMMENT 'string'*/
    	BEGIN
    
    	END$$
    
    DELIMITER ;
    
  4. Add any parameters between the brackets, for example (IN p_month DATE), and write the body between BEGIN and END. The characteristics in the comment are optional.

  5. Press F9, or click Execute query on the toolbar.

The Messages tab shows whether the server accepted it. If the procedure does not appear in the Object Browser, press F5.

Why DELIMITER

The body contains semicolons, which would normally end the statement early. DELIMITER $$ tells bonSQL to treat $$ as the end of a statement until DELIMITER ; puts it back. Keep both lines, and keep $$ after END.

Running the editor tab

In an object editor tab, F9, Ctrl+F9 and the toolbar’s Execute query button all run the whole tab. F8 is not available there. In SQLyog Community the Execute button was greyed out in these tabs; in bonSQL it works.

Changing a procedure

Select the procedure and choose Others > Stored Procedures > Alter Stored Procedure… (F6). The tab that opens holds three statements between the DELIMITER lines:

DELIMITER $$

USE `shop`$$

DROP PROCEDURE IF EXISTS `close_month`$$

CREATE ... (the current definition, read from the server) ... END$$

DELIMITER ;

Edit the CREATE part and execute the tab. The procedure is dropped and created again in one run.

If the server rejects the new CREATE, the drop has already happened and the procedure is gone. Your text is still in the tab: correct the error and execute it again.

Dropping a procedure

Select it and choose Others > Stored Procedures > Drop Stored Procedure… (Del). bonSQL asks you to confirm, then drops it and removes it from the Object Browser.

Running a procedure

Call it from a query tab, for example CALL close_month('2026-09-01');, and press F9.