What is the use of DELIMETER command in MySQL?
What is the use of DELIMETER command in MySQL?
The DELIMITER
command in MySQL is used to define a custom delimiter for SQL statements, primarily to facilitate the creation and execution of stored procedures, functions, and triggers. By default, MySQL uses the semicolon (;
) as the delimiter to separate individual SQL statements. However, when defining stored procedures, functions, or triggers, which themselves contain multiple SQL statements separated by semicolons, using the default semicolon delimiter can cause issues. This is because MySQL could misinterpret the end of a single SQL statement within the stored procedure as the end of the entire procedure.
To avoid this problem, the DELIMITER
command allows developers to temporarily change the delimiter to another character or sequence of characters, such as //
or $$
, that does not conflict with the semicolons used within the stored procedure's SQL statements. This custom delimiter marks the end of the entire stored procedure, function, or trigger definition, allowing it to be passed to the server as a single statement. Once the definition is complete, the delimiter can be changed back to the default semicolon, enabling normal SQL statement execution to resume.
The use of a custom delimiter is crucial when working with stored procedures, functions, or triggers in MyS...
middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào