{"id":200723,"date":"2025-05-06T14:21:51","date_gmt":"2025-05-06T06:21:51","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200723\/"},"modified":"2025-05-06T14:21:51","modified_gmt":"2025-05-06T06:21:51","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e8%ae%be%e5%a4%87%e7%b1%bb%e5%88%ab%e8%a1%a8%e6%95%b0%e6%8d%ae%e5%a1%ab%e5%85%85%e8%87%b3%e8%ae%be%e5%a4%87%e8%a1%a8%e4%b8%ad%e7%9a%84-device_category_name-%e5%ad%97","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200723\/","title":{"rendered":"\u5982\u4f55\u5c06\u8bbe\u5907\u7c7b\u522b\u8868\u6570\u636e\u586b\u5145\u81f3\u8bbe\u5907\u8868\u4e2d\u7684 device_category_name \u5b57\u6bb5\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u5c06\u8bbe\u5907\u7c7b\u522b\u8868\u6570\u636e\u586b\u5145\u81f3\u8bbe\u5907\u8868\u4e2d\u7684 device_category_name \u5b57\u6bb5\uff1f<\/h1>\n<p>\u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\u4e3b\u673a\u5b9d\u8d1d\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241112\/173140545667332690dc409.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u901a\u8fc7\u4e2d\u95f4\u67e5\u8be2\u7ed3\u679c\u586b\u5145\u6570\u636e<\/strong><\/p>\n<p>\u5728\u5df2\u6709\u7684\u8bbe\u5907\u7c7b\u522b\u8868\u548c\u8bbe\u5907\u8868\u7684\u57fa\u7840\u4e0a\uff0c\u7cfb\u7edf\u9700\u8981\u6dfb\u52a0\u4e00\u4e2a\u5b57\u6bb5 device_category_name \u5230\u8bbe\u5907\u8868\u4e2d\uff0c\u5e76\u4f7f\u7528\u8bbe\u5907\u7c7b\u522b\u8868\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u586b\u5145\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p><strong>1. \u51c6\u5907\u5de5\u4f5c<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u5728\u8bbe\u5907\u8868\u4e2d\u6dfb\u52a0 device_category_name \u5217\uff1a<\/p>\n<pre>alter table device add column device_category_name varchar(100);<\/pre>\n<p><strong>2. \u66f4\u65b0\u6570\u636e<\/strong><\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528\u4e2d\u95f4\u67e5\u8be2\u7ed3\u679c\u6765\u66f4\u65b0\u6570\u636e\uff1a<\/p>\n<pre>UPDATE device, device_category AS dc\nSET device.device_category_name = dc.name\nWHERE dc.id = device.device_category_id;<\/pre>\n<p>\u8be5\u67e5\u8be2\u5c06\u9010\u884c\u5339\u914d\u8bbe\u5907\u8868\u548c\u8bbe\u5907\u7c7b\u522b\u8868\u4e2d\u7684\u8bb0\u5f55\uff0c\u5e76\u5c06\u8bbe\u5907\u7c7b\u522b\u8868\u4e2d\u7684 name \u590d\u5236\u5230\u8bbe\u5907\u8868\u4e2d\u7684 device_category_name \u5217\u4e2d\u3002<\/p>\n<p><strong>3. \u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<p>\u5728\u6267\u884c\u4e0a\u8ff0\u64cd\u4f5c\u524d\uff0c<strong>\u8bf7\u52a1\u5fc5\u5907\u4efd\u6570\u636e<\/strong>\u3002\u53e6\u5916\uff0c\u8bf7\u786e\u4fdd\u8bbe\u5907\u7c7b\u522b\u8868\u548c\u8bbe\u5907\u8868\u7684 id \u5217\u5177\u6709\u552f\u4e00\u7ea6\u675f\uff0c\u4ee5\u907f\u514d\u6570\u636e\u4e0d\u4e00\u81f4\u3002<\/p>\n<p><strong>4. \u5728\u7ebf\u6d4b\u8bd5<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 [sql fiddle](http:\/\/sqlfiddle.com\/#!9\/628d9f\/1) \u5728\u7ebf\u6d4b\u8bd5\u4e0a\u8ff0\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u5982\u4f55\u5c06\u8bbe\u5907\u7c7b\u522b\u8868\u6570\u636e\u586b\u5145\u81f3\u8bbe\u5907\u8868\u4e2d\u7684 device_category_name \u5b57\u6bb5\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6570\u636e\u5e93\u77e5\u8bc6\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5c06\u8bbe\u5907\u7c7b\u522b\u8868\u6570\u636e\u586b\u5145\u81f3\u8bbe\u5907\u8868&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200723","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200723","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200723"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200723\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}