简体   繁体   中英

How to create snippet in MySQL Workbench?

I'm looking for a snippet(template) that will create a procedure and also do exception handling. I know there are already some snippets for different operations but I want to add my own snippet.

There's a litte button to add the entire content of the current editor or only its selection (if any) in the snippet toolbar:

在此输入图像描述

  1. Snippet is a programming term for a small region of re-usable source code, machine code, or text.
  2. For MySQL Workbench all snippets are located in “C:\\Program Files (x86)\\MySQL\\MySQL Workbench 6.0 CE\\snippets”. If you want add your own snippet you can add it in the above directory else you can also edit the existing one.
  3. Below is the sample snippet which will create stored procedure with exception handling.

     CREATE PROCEDURE Syntax DELIMITER $$ CREATE PROCEDURE `new_procedure` () BEGIN /* Created By - Discription - --------------------------- Modified By - Discription - */ DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN rollback; GET DIAGNOSTICS CONDITION 1 @errorNo = MYSQL_ERRNO, @errorText = MESSAGE_TEXT; SET @spName = 'new_procedure'; # SELECT concat('[',@spName,']-(',@errorNo,'-',@errorText,')'); INSERT INTO errorlogs (ErrorType, `Error`, DateCreated) VALUES (4, concat('[',@spName,']-(',@errorNo,'-',@errorText,')'), now()); END; SET autocommit = 0; START TRANSACTION; ##################### #Put your logic here ##################### COMMIT; END 
  4. Save the above file as 'CustomeSnippet.txt' and add it in “C:\\Program Files (x86)\\MySQL\\MySQL Workbench 6.0 CE\\snippets”.

  5. Now open your MySQL workbench and connect to your database. In the right side bar you will find your 'CustomeSnippet' listed in the dropdown. 在此输入图像描述

  6. Use it and enjoy coding :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM