{"id":187262,"date":"2024-11-11T12:48:32","date_gmt":"2024-11-11T04:48:32","guid":{"rendered":"https:\/\/server.hk\/cnblog\/187262\/"},"modified":"2024-11-11T12:48:33","modified_gmt":"2024-11-11T04:48:33","slug":"%e6%95%b8%e6%93%9a%e5%ba%ab%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e4%bf%ae%e6%94%b9%e6%95%99%e7%a8%8b-%e6%95%b8%e6%93%9a%e5%ba%ab%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/187262\/","title":{"rendered":"\u6578\u64da\u5eab\u6578\u64da\u985e\u578b\u4fee\u6539\u6559\u7a0b (\u6578\u64da\u5eab\u5982\u4f55\u4fee\u6539\u6578\u64da\u985e\u578b)"},"content":{"rendered":"<h1 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e4%bf%ae%e6%94%b9%e6%95%99%e7%a8%8b-%e6%95%b8%e6%93%9a%e5%ba%ab%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-aRvzJlEYCw\">\u6578\u64da\u5eab\u6578\u64da\u985e\u578b\u4fee\u6539\u6559\u7a0b (\u6578\u64da\u5eab\u5982\u4f55\u4fee\u6539\u6578\u64da\u985e\u578b)<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0c\u6578\u64da\u985e\u578b\u7684\u9078\u64c7\u5c0d\u65bc\u6578\u64da\u7684\u5b58\u5132\u548c\u64cd\u4f5c\u81f3\u95dc\u91cd\u8981\u3002\u96a8\u8457\u696d\u52d9\u9700\u6c42\u7684\u8b8a\u5316\uff0c\u53ef\u80fd\u9700\u8981\u5c0d\u73fe\u6709\u6578\u64da\u985e\u578b\u9032\u884c\u4fee\u6539\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728\u5e38\u898b\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u4e2d\u4fee\u6539\u6578\u64da\u985e\u578b\uff0c\u5305\u62ec MySQL\u3001PostgreSQL \u548c SQL Server\uff0c\u4e26\u63d0\u4f9b\u76f8\u61c9\u7684\u793a\u4f8b\u548c\u6b65\u9a5f\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e4%bf%ae%e6%94%b9%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-aRvzJlEYCw\">\u70ba\u4ec0\u9ebc\u9700\u8981\u4fee\u6539\u6578\u64da\u985e\u578b<\/h2>\n<p>\u6578\u64da\u985e\u578b\u7684\u4fee\u6539\u901a\u5e38\u662f\u7531\u65bc\u4ee5\u4e0b\u5e7e\u500b\u539f\u56e0\uff1a<\/p>\n<ul>\n<li><strong>\u696d\u52d9\u9700\u6c42\u8b8a\u66f4\uff1a<\/strong>\u96a8\u8457\u696d\u52d9\u7684\u767c\u5c55\uff0c\u53ef\u80fd\u9700\u8981\u5b58\u5132\u66f4\u5927\u7684\u6578\u64da\u6216\u4e0d\u540c\u985e\u578b\u7684\u6578\u64da\u3002<\/li>\n<li><strong>\u6027\u80fd\u512a\u5316\uff1a<\/strong>\u67d0\u4e9b\u6578\u64da\u985e\u578b\u53ef\u80fd\u6703\u5f71\u97ff\u67e5\u8a62\u6027\u80fd\uff0c\u4fee\u6539\u70ba\u66f4\u5408\u9069\u7684\u985e\u578b\u53ef\u4ee5\u63d0\u9ad8\u6548\u7387\u3002<\/li>\n<li><strong>\u6578\u64da\u4e00\u81f4\u6027\uff1a<\/strong>\u70ba\u4e86\u4fdd\u6301\u6578\u64da\u7684\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\uff0c\u53ef\u80fd\u9700\u8981\u8abf\u6574\u6578\u64da\u985e\u578b\u4ee5\u7b26\u5408\u65b0\u7684\u6a19\u6e96\u3002<\/li>\n<\/ul>\n<h2 id=\"mysql-%e4%b8%ad%e4%bf%ae%e6%94%b9%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-aRvzJlEYCw\">MySQL \u4e2d\u4fee\u6539\u6578\u64da\u985e\u578b<\/h2>\n<p>\u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>ALTER TABLE<\/code> \u8a9e\u53e5\u4f86\u4fee\u6539\u6578\u64da\u985e\u578b\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u8a9e\u6cd5\uff1a<\/p>\n<pre><code>ALTER TABLE \u8868\u540d MODIFY COLUMN \u5217\u540d \u65b0\u6578\u64da\u985e\u578b;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u6211\u5011\u6709\u4e00\u500b\u540d\u70ba <code>users<\/code> \u7684\u8868\uff0c\u4e26\u5e0c\u671b\u5c07 <code>age<\/code> \u5217\u7684\u6578\u64da\u985e\u578b\u5f9e <code>INT<\/code> \u4fee\u6539\u70ba <code>TINYINT<\/code>\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>ALTER TABLE users MODIFY COLUMN age TINYINT;<\/code><\/pre>\n<h2 id=\"postgresql-%e4%b8%ad%e4%bf%ae%e6%94%b9%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-aRvzJlEYCw\">PostgreSQL \u4e2d\u4fee\u6539\u6578\u64da\u985e\u578b<\/h2>\n<p>\u5728 PostgreSQL \u4e2d\uff0c\u4fee\u6539\u6578\u64da\u985e\u578b\u7684\u8a9e\u6cd5\u8207 MySQL \u985e\u4f3c\uff0c\u4f46\u9700\u8981\u4f7f\u7528 <code>ALTER COLUMN<\/code>\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u8a9e\u6cd5\uff1a<\/p>\n<pre><code>ALTER TABLE \u8868\u540d ALTER COLUMN \u5217\u540d SET DATA TYPE \u65b0\u6578\u64da\u985e\u578b;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5c07 <code>users<\/code> \u8868\u4e2d\u7684 <code>birthdate<\/code> \u5217\u7684\u6578\u64da\u985e\u578b\u5f9e <code>DATE<\/code> \u4fee\u6539\u70ba <code>TIMESTAMP<\/code>\uff1a<\/p>\n<pre><code>ALTER TABLE users ALTER COLUMN birthdate SET DATA TYPE TIMESTAMP;<\/code><\/pre>\n<h2 id=\"sql-server-%e4%b8%ad%e4%bf%ae%e6%94%b9%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-aRvzJlEYCw\">SQL Server \u4e2d\u4fee\u6539\u6578\u64da\u985e\u578b<\/h2>\n<p>\u5728 SQL Server \u4e2d\uff0c\u4fee\u6539\u6578\u64da\u985e\u578b\u7684\u8a9e\u6cd5\u4e5f\u985e\u4f3c\uff0c\u4f7f\u7528 <code>ALTER TABLE<\/code> \u548c <code>ALTER COLUMN<\/code>\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u8a9e\u6cd5\uff1a<\/p>\n<pre><code>ALTER TABLE \u8868\u540d ALTER COLUMN \u5217\u540d \u65b0\u6578\u64da\u985e\u578b;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5c07 <code>products<\/code> \u8868\u4e2d\u7684 <code>price<\/code> \u5217\u7684\u6578\u64da\u985e\u578b\u5f9e <code>MONEY<\/code> \u4fee\u6539\u70ba <code>DECIMAL(10, 2)<\/code>\uff1a<\/p>\n<pre><code>ALTER TABLE products ALTER COLUMN price DECIMAL(10, 2);<\/code><\/pre>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-aRvzJlEYCw\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4fee\u6539\u6578\u64da\u985e\u578b\u4e4b\u524d\uff0c\u61c9\u8003\u616e\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u517c\u5bb9\u6027\uff1a<\/strong>\u78ba\u4fdd\u65b0\u6578\u64da\u985e\u578b\u80fd\u5920\u517c\u5bb9\u73fe\u6709\u6578\u64da\uff0c\u5426\u5247\u53ef\u80fd\u6703\u5c0e\u81f4\u6578\u64da\u4e1f\u5931\u6216\u932f\u8aa4\u3002<\/li>\n<li><strong>\u5099\u4efd\u6578\u64da\uff1a<\/strong>\u5728\u9032\u884c\u4efb\u4f55\u7d50\u69cb\u6027\u8b8a\u66f4\u4e4b\u524d\uff0c\u52d9\u5fc5\u5099\u4efd\u6578\u64da\uff0c\u4ee5\u9632\u6b62\u610f\u5916\u60c5\u6cc1\u767c\u751f\u3002<\/li>\n<li><strong>\u6e2c\u8a66\u74b0\u5883\uff1a<\/strong>\u5728\u751f\u7522\u74b0\u5883\u4e2d\u9032\u884c\u4fee\u6539\u4e4b\u524d\uff0c\u5efa\u8b70\u5728\u6e2c\u8a66\u74b0\u5883\u4e2d\u9032\u884c\u5145\u5206\u6e2c\u8a66\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-aRvzJlEYCw\">\u7e3d\u7d50<\/h2>\n<p>\u4fee\u6539\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u985e\u578b\u662f\u4e00\u9805\u91cd\u8981\u7684\u7ba1\u7406\u4efb\u52d9\uff0c\u80fd\u5920\u5e6b\u52a9\u4f01\u696d\u66f4\u597d\u5730\u9069\u61c9\u4e0d\u65b7\u8b8a\u5316\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f\u5728 MySQL\u3001PostgreSQL \u9084\u662f SQL Server \u4e2d\uff0c\u6b63\u78ba\u7684\u64cd\u4f5c\u6b65\u9a5f\u548c\u6ce8\u610f\u4e8b\u9805\u90fd\u80fd\u78ba\u4fdd\u6578\u64da\u7684\u5b89\u5168\u548c\u5b8c\u6574\u6027\u3002\u5982\u679c\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728\u6578\u64da\u5eab\u4e2d\u4fee\u6539\u6578\u64da\u985e\u578b\uff0c\u638c\u63e1\u6b65\u9a5f\u548c\u6280\u5de7\uff0c\u78ba\u4fdd\u6578\u64da\u5b8c\u6574\u6027\u8207\u6027\u80fd\u512a\u5316\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-187262","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/187262","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=187262"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/187262\/revisions"}],"predecessor-version":[{"id":187263,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/187262\/revisions\/187263"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=187262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=187262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=187262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}