{"id":241,"date":"2019-03-09T23:03:52","date_gmt":"2019-03-09T14:03:52","guid":{"rendered":"https:\/\/took.jp\/?p=241"},"modified":"2020-06-15T17:00:43","modified_gmt":"2020-06-15T08:00:43","slug":"mysql_line_copy","status":"publish","type":"post","link":"https:\/\/took.jp\/tech-blog\/mysql_line_copy\/","title":{"rendered":"MySQL\u3000\u30ec\u30b3\u30fc\u30c9\u3092\u8907\u88fd\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p><span style=\"color: #000000;\">\u30ec\u30b3\u30fc\u30c9\u3092\u8907\u88fd\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3044\u305f\u3057\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">\u3053\u3061\u3089\u306f\u3001MySQL\u3067\u66f8\u3044\u3066\u3044\u307e\u3059\u304c\u3001\u4ed6\u306eSQL\u3067\u3082\u307b\u3068\u3093\u3069\u5909\u308f\u3089\u305a\u306b\u5229\u7528\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\n<p>$id\u90e8\u5206\u306b\u306f\u8907\u88fd\u3057\u305f\u3044\u30ec\u30b3\u30fc\u30c9\u306eid\u3092\u3044\u308c\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><\/span><\/p>\n<h2>\u9055\u3046\u30c6\u30fc\u30d6\u30eb\u306e\u30ec\u30b3\u30fc\u30c9\uff08\u884c\uff09\u3092\u8907\u88fd\u3059\u308b\u3002<\/h2>\n<p>&nbsp;<\/p>\n<pre class=\"line-numbers\"><code class=\"language-sql\">INSERT INTO test\u00a0SELECT * FROM test2 WHERE id= $id;<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">\u3053\u306e\u5834\u5408\u306f\u3001\u7c21\u5358\u3067\u3059\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u3053\u306e\u6587\u3067\u306f\u3001test\u30c6\u30fc\u30d6\u30eb\u306btest2\u30c6\u30fc\u30d6\u30eb\u306e\u6307\u5b9a\u3057\u305fid\u3068\u4e00\u81f4\u3059\u308b\u30c7\u30fc\u30bf\u3092\u633f\u5165\u3057\u3066\u3044\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><\/span><\/p>\n<h2>\u540c\u3058\u30c6\u30fc\u30d6\u30eb\u306e\u30ec\u30b3\u30fc\u30c9\uff08\u884c\uff09\u3092\u8907\u88fd\u3059\u308b\u3002<\/h2>\n<p>&nbsp;<\/p>\n<pre class=\"line-numbers\"><code class=\"language-php\">CREATE TEMPORARY TABLE tmp_test LIKE test;\r\nINSERT INTO tmp_test SELECT * FROM test WHERE id= id ;\r\nUPDATE tmp_test set id = (SELECT MAX(id) FROM test)+1;\r\nINSERT INTO test SELECT * FROM tmp_test;<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\">\u540c\u3058\u30c6\u30fc\u30d6\u30eb\u306e\u30ec\u30b3\u30fc\u30c9\u3092\u8907\u88fd\u3059\u308b\u5834\u5408\u306f\u3001\u4e00\u5ea6\u4ed6\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u30c7\u30fc\u30bf\u3092\u6301\u3063\u3066\u884c\u3063\u3066\u3084\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u4e0a\u8a18\u306e\u51e6\u7406\u3067\u306f\u3001\u63a5\u7d9a\u3057\u305f\u30bb\u30c3\u30b7\u30e7\u30f3\u306e\u9593\u3060\u3051\u5b58\u5728\u3059\u308bTMPPORARY TABLE\u3092\u4f5c\u6210\u3057\u3001test\u30c6\u30fc\u30d6\u30eb\u306eDDL\uff08\u69cb\u9020\uff09\u306e\u307f\u3092\u30b3\u30d4\u30fc\u3057\u3066\u3044\u307e\u3059\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u305d\u306e\u5f8c\u3001test\u30c6\u30fc\u30d6\u30eb\u306eid\u3068\u4e00\u81f4\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u3092tmp_test\u30c6\u30fc\u30d6\u30eb\u306b\u633f\u5165\u3057\u3001<\/span><\/p>\n<p><span style=\"color: #000000;\">id\u3092test\u30c6\u30fc\u30d6\u30eb\u306e\u6700\u5927\u5024\u3088\u308a1\u5897\u3084\u3057\u3066\u3044\u307e\u3059\u3002\uff08id\u3092\u4e3b\u30ad\u30fc\u3068\u3057\u3066\u3044\u308b\u5834\u5408\u3001\u4e00\u610f\u306e\u5024\u3067\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u305f\u3081\uff09<\/span><\/p>\n<p><span style=\"color: #000000;\">\u6700\u5f8c\u306b\u3001tmp_test\u30c6\u30fc\u30d6\u30eb\u306e\u30ec\u30b3\u30fc\u30c9\u3092test\u30c6\u30fc\u30d6\u30eb\u306b\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30ec\u30b3\u30fc\u30c9\u3092\u8907\u88fd\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3044\u305f\u3057\u307e\u3059\u3002 &nbsp; &nbsp; \u3053\u3061\u3089\u306f\u3001MySQL\u3067\u66f8\u3044\u3066\u3044\u307e\u3059\u304c\u3001\u4ed6\u306eSQL\u3067\u3082\u307b\u3068\u3093\u3069\u5909\u308f\u3089\u305a\u306b\u5229\u7528\u3067\u304d\u307e\u3059\u3002 $id\u90e8\u5206\u306b\u306f\u8907\u88fd\u3057\u305f\u3044\u30ec\u30b3\u30fc\u30c9\u306eid\u3092\u3044\u308c\u3066\u304f\u3060\u3055\u3044\u3002 &nbsp; \u9055\u3046\u30c6\u30fc\u30d6\u2026<\/p>\n","protected":false},"author":3,"featured_media":2006,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62,71],"tags":[],"class_list":["post-241","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-it","category-mysql"],"_links":{"self":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts\/241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/comments?post=241"}],"version-history":[{"count":0,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts\/241\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/media\/2006"}],"wp:attachment":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/media?parent=241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/categories?post=241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/tags?post=241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}