[英]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: 有一个litte按钮可以添加当前编辑器的全部内容或仅添加其在片段工具栏中的选择(如果有):
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
Save the above file as 'CustomeSnippet.txt' and add it in “C:\\Program Files (x86)\\MySQL\\MySQL Workbench 6.0 CE\\snippets”. 将上述文件保存为“CustomeSnippet.txt”并将其添加到“C:\\ Program Files(x86)\\ MySQL \\ MySQL Workbench 6.0 CE \\ snippets”中。
Now open your MySQL workbench and connect to your database. 现在打开MySQL工作台并连接到您的数据库。 In the right side bar you will find your 'CustomeSnippet' listed in the dropdown. 在右侧栏中,您会在下拉列表中找到“CustomeSnippet”。
Use it and enjoy coding :-) 使用它并享受编码:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.