è£MySQL ã¯ã¨ãªã¼å ¥é (9) åºç¤ç·¨7 åçã¯ã¨ãªã¼
MySQLã§åçã¯ã¨ãªã¼ãå®è¡ããçºã«プリペアド ステートメントã使ãã¾ãã
PREPAREã§SQLãå®ç¾©ããEXECUTEã§PREPAREã§å®ç¾©ããSQLãå®è¡ãã¾ãã
PREPARE stmt_name FROM preparable_stmt EXECUTE stmt_name [USING @var_name [, @var_name] ...]
SET @tbl:='pref'; SET @pkey:=(SELECT COLUMN_NAME FROM information_schema.`COLUMNS` WHERE TABLE_NAME=@tbl AND COLUMN_KEY='PRI'); SET @updates:=(SELECT GROUP_CONCAT(CONCAT('\'',COLUMN_NAME,'=\\\'\',',COLUMN_NAME,',\'\\\'\',') SEPARATOR '\',\',') FROM information_schema.`COLUMNS` WHERE TABLE_NAME=@tbl AND COLUMN_KEY<>'PRI'); SET @sql:=CONCAT('SELECT CONCAT(\'UPDATE ',@tbl,' SET \',',@updates,'\' WHERE ',@pkey,'=\',',@pkey,',\'\\\'\') FROM ',@tbl); PREPARE update_backup FROM @sql; EXECUTE update_backup;
â» 7/9 å®éã«åããã®ã«ç½®ãæããæ¥æ¬èªãæååããããã¨ã¹ã±ã¼ããå®ç§ã§ã¯ãªãã®ã§ãå¾æ¥æ¹ãã¦å·®ãæ¿ãã¾ãã