liveBook · Manning

Delimiter

As explained in Learn SQL in a Month of Lunches

DELIMITER is a MySQL-specific command that changes the marker used to recognize the end of SQL statements or stored procedures.

DELIMITER is a MySQL-specific command for temporarily changing the marker that signals the end of a SQL statement. It matters when defining a stored procedure because the procedure contains several statements, each normally ending with a semicolon. Without a different marker, MySQL could treat the first internal semicolon as the end of the entire procedure. section 20.2.1

Creating a stored procedure

Change the delimiter to double slashes, define the procedure with its normal internal semicolons, close the procedure with //, and restore the semicolon afterward. The resulting GetTitleCategory procedure joins title and category data; CALL GetTitleCategory executes it. section 20.2.1

DELIMITER //                                    #1
 
CREATE PROCEDURE GetTitleCategory()             #2
BEGIN                                           #3
SELECT                                          #4
    t.TitleName,
    c.CategoryName
 FROM title t
INNER JOIN category c
    ON t.CategoryID = c.CategoryID;
END //                                          #5
 
DELIMITER ;                                     #6

This listing shows the complete delimiter sequence: switch to //, create the procedure, terminate it with //, and switch back to ;. section 20.2.1

Use the pattern consistently:

  • Issue DELIMITER // before the CREATE PROCEDURE statement. section 20.2.1
  • Keep semicolons inside the procedure for its individual SQL statements. section 20.2.1
  • End the procedure with END //, then restore DELIMITER ; for ordinary queries. section 20.2.1
  • Apply the same pattern to conditional procedures such as AddPromotion, whose IF block contains an INSERT statement. section 21.2.1

DELIMITER changes how the procedure definition is terminated; it does not replace the semicolons that separate statements inside the procedure. Procedure syntax and execution vary among database products, so this command should not be treated as portable SQL. section 20.2.1 section 21.2.1

How Learn SQL in a Month of Lunches covers it

How deep it goes
Explains the delimiter conflict, demonstrates changing and restoring it, and stops short of broader procedure internals.
Examples
Demonstrates GetTitleCategory and AddPromotion with // as the temporary procedure terminator.
What it assumes
Assumes familiarity with semicolon-terminated SQL queries and introduces the delimiter conflict through stored-procedure creation.
What you can do after
Operate/configure MySQL stored-procedure definitions by changing and restoring the statement delimiter correctly.
How it connects
Connects stored procedures with SQL statements, semicolons, statement terminators, conditional logic, and CALL execution.

Also explained in

Compare how 11 books explain delimiter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn SQL in a Month of Lunches. The section links point to the parts of the book it draws on.