0
0
SQLquery~10 mins

CREATE PROCEDURE syntax in SQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - CREATE PROCEDURE syntax
Start CREATE PROCEDURE
Define Procedure Name
Specify Parameters (optional)
Write Procedure Body
End with DELIMITER or END
Procedure Stored in Database
This flow shows how a stored procedure is created step-by-step: naming it, adding parameters, writing the body, and saving it.
Execution Sample
SQL
DELIMITER $$
CREATE PROCEDURE greetUser(IN userName VARCHAR(50))
BEGIN
  SELECT CONCAT('Hello, ', userName) AS greeting;
END$$
DELIMITER ;
This code creates a procedure named greetUser that takes a name and returns a greeting message.
Execution Table
StepActionEvaluationResult
1Set DELIMITER to $$DELIMITER changedAllows procedure body with semicolons
2CREATE PROCEDURE greetUserProcedure name setProcedure greetUser defined
3Define parameter IN userName VARCHAR(50)Parameter acceptedInput parameter userName ready
4BEGIN block startsProcedure body beginsReady to write SQL statements
5SELECT CONCAT('Hello, ', userName) AS greeting;Concatenate stringReturns greeting message
6END block endsProcedure body endsProcedure body complete
7DELIMITER reset to ;DELIMITER restoredProcedure stored successfully
💡 Procedure creation ends after DELIMITER reset; procedure is stored in database.
Variable Tracker
VariableStartAfter Step 3After Step 5Final
userNameundefinedInput parameter definedUsed in CONCATInput parameter used in procedure
Key Moments - 3 Insights
Why do we change the DELIMITER before and after creating the procedure?
We change DELIMITER (see execution_table step 1 and 7) to allow semicolons inside the procedure body without ending the CREATE statement early.
What does the IN keyword before userName mean?
IN means userName is an input parameter to the procedure (execution_table step 3), so the caller must provide a value.
Why do we use BEGIN and END inside the procedure?
BEGIN and END (steps 4 and 6) group multiple SQL statements as the procedure body, even if there is only one statement.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what happens at step 5?
AThe greeting message is created using CONCAT
BThe procedure name is set
CThe DELIMITER is reset
DThe parameter userName is defined
💡 Hint
Check the Action and Evaluation columns at step 5 in the execution_table
At which step does the procedure body start?
AStep 2
BStep 4
CStep 3
DStep 6
💡 Hint
Look for 'BEGIN block starts' in the Action column of execution_table
If we did not change the DELIMITER at step 1, what would happen?
AThe parameter would not be recognized
BThe procedure would be created successfully
CThe CREATE PROCEDURE statement would end too early at the first semicolon
DThe procedure body would be ignored
💡 Hint
Refer to the key_moments explanation about DELIMITER usage
Concept Snapshot
CREATE PROCEDURE syntax:
DELIMITER $$
CREATE PROCEDURE procName([IN|OUT|INOUT] param datatype)
BEGIN
  -- SQL statements;
END$$
DELIMITER ;
Use DELIMITER to allow semicolons inside procedure body.
Parameters can be input (IN), output (OUT), or both (INOUT).
Full Transcript
Creating a stored procedure in SQL involves several steps. First, we change the DELIMITER to allow semicolons inside the procedure body without ending the statement early. Then, we write CREATE PROCEDURE followed by the procedure name and optional parameters. The procedure body is enclosed between BEGIN and END, where SQL statements are written. Finally, we reset the DELIMITER to the default. This process stores the procedure in the database for later use.