Last active
November 5, 2015 08:42
-
-
Save KimiyukiYamauchi/b68bfae07f88e2845e5f to your computer and use it in GitHub Desktop.
引数で指定した名前でtb1テーブルのコピーを作成するストアードプロシージャ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop procedure if exists tb1X; | |
delimiter // | |
create procedure tb1X(in x varchar(100)) | |
begin | |
set @s = concat('drop table if exists `', x ,'`'); | |
prepare stmt from @s; | |
execute stmt; | |
deallocate prepare stmt; | |
set @s = concat('create table `', x ,'` select * from tb1'); | |
prepare stmt from @s; | |
execute stmt; | |
deallocate prepare stmt; | |
end | |
// | |
delimiter ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方は以下
mysql> call tb1X('tb1A');
=> これで、「tb1」テーブルをコピーした「tb1A」テーブルが作成される