0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MySQLでtruncate tableするためのストアドプロシージャ

Posted at

WorkatoではOn-prem Agent経由以外で任意のSQLを実行することが出来ません。

On-prem Agentを利用しない環境で任意のSQLを実行したい場合は、実行したいSQLをストアドプロシージャとして実装し、それを実行して対応することになります。

以下は、MySQLでtruncate tableするためのストアドプロシージャです。

※以下のコードはWorkato専用ではなく、MySQL/MariaDBで汎用的に利用可能です。

コード

drop procedure if exists truncate_table;
delimiter //
create procedure truncate_table (IN table_name varchar(20)) 
BEGIN
    SET @sql = CONCAT('truncate table ', table_name, ';');
    PREPARE stmt FROM @sql; 
    EXECUTE stmt; 
END;
//
delimiter ;

実行

以下の文を実行することで、指定されたテーブルをtruncateすることが可能です。

call truncate_table('<テーブル名>')
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?