{"id":173421,"date":"2024-11-07T17:53:27","date_gmt":"2024-11-07T09:53:27","guid":{"rendered":"https:\/\/server.hk\/cnblog\/173421\/"},"modified":"2024-11-07T17:53:28","modified_gmt":"2024-11-07T09:53:28","slug":"%e5%a6%82%e4%bd%95%e6%9b%b4%e6%94%b9%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%9a%84%e5%88%97%e5%b1%ac%e6%80%a7%ef%bc%9f-%e6%95%b8%e6%93%9a%e5%ba%ab%e6%9b%b4%e6%94%b9%e5%88%97%e5%b1%ac%e6%80%a7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/173421\/","title":{"rendered":"\u5982\u4f55\u66f4\u6539\u6578\u64da\u5eab\u4e2d\u7684\u5217\u5c6c\u6027\uff1f (\u6578\u64da\u5eab\u66f4\u6539\u5217\u5c6c\u6027)"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e6%9b%b4%e6%94%b9%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%9a%84%e5%88%97%e5%b1%ac%e6%80%a7%ef%bc%9f-%e6%95%b8%e6%93%9a%e5%ba%ab%e6%9b%b4%e6%94%b9%e5%88%97%e5%b1%ac%e6%80%a7-XxrUmVEdqu\">\u5982\u4f55\u66f4\u6539\u6578\u64da\u5eab\u4e2d\u7684\u5217\u5c6c\u6027\uff1f (\u6578\u64da\u5eab\u66f4\u6539\u5217\u5c6c\u6027)<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0c\u5217\u5c6c\u6027\u662f\u6307\u8868\u4e2d\u6bcf\u4e00\u5217\u7684\u7279\u6027\uff0c\u5305\u62ec\u6578\u64da\u985e\u578b\u3001\u9577\u5ea6\u3001\u7d04\u675f\u689d\u4ef6\u7b49\u3002\u96a8\u8457\u696d\u52d9\u9700\u6c42\u7684\u8b8a\u5316\uff0c\u53ef\u80fd\u9700\u8981\u5c0d\u6578\u64da\u5eab\u4e2d\u7684\u5217\u5c6c\u6027\u9032\u884c\u8abf\u6574\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728\u4e0d\u540c\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u4e2d\u66f4\u6539\u5217\u5c6c\u6027\uff0c\u4e26\u63d0\u4f9b\u76f8\u61c9\u7684\u793a\u4f8b\u548c\u6ce8\u610f\u4e8b\u9805\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e6%9b%b4%e6%94%b9%e5%88%97%e5%b1%ac%e6%80%a7%ef%bc%9f-XxrUmVEdqu\">\u70ba\u4ec0\u9ebc\u9700\u8981\u66f4\u6539\u5217\u5c6c\u6027\uff1f<\/h2>\n<p>\u66f4\u6539\u5217\u5c6c\u6027\u901a\u5e38\u662f\u56e0\u70ba\u4ee5\u4e0b\u5e7e\u500b\u539f\u56e0\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u985e\u578b\u8b8a\u66f4\uff1a<\/strong>\u96a8\u8457\u696d\u52d9\u9700\u6c42\u7684\u8b8a\u5316\uff0c\u53ef\u80fd\u9700\u8981\u5c07\u67d0\u4e00\u5217\u7684\u6578\u64da\u985e\u578b\u5f9e\u6574\u6578\u66f4\u6539\u70ba\u6d6e\u9ede\u6578\uff0c\u6216\u5f9e\u5b57\u7b26\u578b\u66f4\u6539\u70ba\u65e5\u671f\u578b\u3002<\/li>\n<li><strong>\u7d04\u675f\u689d\u4ef6\u8abf\u6574\uff1a<\/strong>\u4f8b\u5982\uff0c\u53ef\u80fd\u9700\u8981\u5c07\u67d0\u4e00\u5217\u7684\u552f\u4e00\u7d04\u675f\u79fb\u9664\uff0c\u6216\u6dfb\u52a0\u975e\u7a7a\u7d04\u675f\u3002<\/li>\n<li><strong>\u6027\u80fd\u512a\u5316\uff1a<\/strong>\u901a\u904e\u66f4\u6539\u5217\u5c6c\u6027\uff0c\u53ef\u4ee5\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\u6216\u6e1b\u5c11\u5b58\u5132\u7a7a\u9593\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%9c%a8%e4%b8%8d%e5%90%8c%e6%95%b8%e6%93%9a%e5%ba%ab%e7%b3%bb%e7%b5%b1%e4%b8%ad%e6%9b%b4%e6%94%b9%e5%88%97%e5%b1%ac%e6%80%a7-XxrUmVEdqu\">\u5728\u4e0d\u540c\u6578\u64da\u5eab\u7cfb\u7d71\u4e2d\u66f4\u6539\u5217\u5c6c\u6027<\/h2>\n<h3 id=\"1-mysql-XxrUmVEdqu\">1. MySQL<\/h3>\n<p>\u5728MySQL\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528ALTER TABLE\u8a9e\u53e5\u4f86\u66f4\u6539\u5217\u5c6c\u6027\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u8a9e\u6cd5\uff1a<\/p>\n<pre><code>ALTER TABLE \u8868\u540d MODIFY \u5217\u540d \u65b0\u6578\u64da\u985e\u578b;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u8981\u5c07\u540d\u70ba\u201cage\u201d\u7684\u5217\u7684\u6578\u64da\u985e\u578b\u5f9eINT\u66f4\u6539\u70baTINYINT\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>ALTER TABLE users MODIFY age TINYINT;<\/code><\/pre>\n<h3 id=\"2-postgresql-XxrUmVEdqu\">2. PostgreSQL<\/h3>\n<p>\u5728PostgreSQL\u4e2d\uff0c\u4fee\u6539\u5217\u5c6c\u6027\u540c\u6a23\u4f7f\u7528ALTER TABLE\u8a9e\u53e5\uff0c\u4f46\u8a9e\u6cd5\u7565\u6709\u4e0d\u540c\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\u201cbirthdate\u201d\u5217\u7684\u6578\u64da\u985e\u578b\u66f4\u6539\u70baDATE\uff1a<\/p>\n<pre><code>ALTER TABLE users ALTER COLUMN birthdate SET DATA TYPE DATE;<\/code><\/pre>\n<h3 id=\"3-sql-server-XxrUmVEdqu\">3. SQL Server<\/h3>\n<p>\u5728SQL Server\u4e2d\uff0c\u4f7f\u7528ALTER TABLE\u8a9e\u53e5\u7684\u8a9e\u6cd5\u5982\u4e0b\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\u201csalary\u201d\u5217\u7684\u6578\u64da\u985e\u578b\u66f4\u6539\u70baDECIMAL(10,2)\uff1a<\/p>\n<pre><code>ALTER TABLE employees ALTER COLUMN salary DECIMAL(10,2);<\/code><\/pre>\n<h3 id=\"4-oracle-XxrUmVEdqu\">4. Oracle<\/h3>\n<p>\u5728Oracle\u4e2d\uff0c\u4fee\u6539\u5217\u5c6c\u6027\u4e5f\u4f7f\u7528ALTER TABLE\u8a9e\u53e5\uff0c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>ALTER TABLE \u8868\u540d MODIFY \u5217\u540d \u65b0\u6578\u64da\u985e\u578b;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5c07\u201cemail\u201d\u5217\u7684\u6578\u64da\u985e\u578b\u66f4\u6539\u70baVARCHAR2(255)\uff1a<\/p>\n<pre><code>ALTER TABLE users MODIFY email VARCHAR2(255);<\/code><\/pre>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-XxrUmVEdqu\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<ul>\n<li>\u5728\u66f4\u6539\u5217\u5c6c\u6027\u4e4b\u524d\uff0c\u5efa\u8b70\u5099\u4efd\u6578\u64da\u5eab\uff0c\u4ee5\u9632\u6b62\u6578\u64da\u4e1f\u5931\u3002<\/li>\n<li>\u67d0\u4e9b\u66f4\u6539\u53ef\u80fd\u6703\u5c0e\u81f4\u6578\u64da\u4e1f\u5931\u6216\u4e0d\u517c\u5bb9\uff0c\u56e0\u6b64\u5728\u57f7\u884c\u66f4\u6539\u4e4b\u524d\uff0c\u61c9\u4ed4\u7d30\u6aa2\u67e5\u6578\u64da\u3002<\/li>\n<li>\u5728\u751f\u7522\u74b0\u5883\u4e2d\u9032\u884c\u66f4\u6539\u6642\uff0c\u61c9\u8003\u616e\u5230\u696d\u52d9\u904b\u884c\u7684\u5f71\u97ff\uff0c\u6700\u597d\u5728\u4f4e\u5cf0\u671f\u9032\u884c\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-XxrUmVEdqu\">\u7e3d\u7d50<\/h2>\n<p>\u66f4\u6539\u6578\u64da\u5eab\u4e2d\u7684\u5217\u5c6c\u6027\u662f\u4e00\u9805\u91cd\u8981\u7684\u6578\u64da\u5eab\u7ba1\u7406\u4efb\u52d9\uff0c\u80fd\u5920\u5e6b\u52a9\u4f01\u696d\u9069\u61c9\u4e0d\u65b7\u8b8a\u5316\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662fMySQL\u3001PostgreSQL\u3001SQL Server\u9084\u662fOracle\uff0c\u901a\u904e\u6b63\u78ba\u7684ALTER TABLE\u8a9e\u53e5\uff0c\u90fd\u80fd\u5920\u6709\u6548\u5730\u9032\u884c\u5217\u5c6c\u6027\u7684\u8abf\u6574\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u7ba1\u7406\u7684\u4f01\u696d\uff0c\u9078\u64c7\u5408\u9069\u7684<a href=\"https:\/\/server.hk\">VPS<\/a>\u6216<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u89e3\u6c7a\u65b9\u6848\uff0c\u80fd\u5920\u63d0\u4f9b\u7a69\u5b9a\u7684\u6578\u64da\u5eab\u904b\u884c\u74b0\u5883\uff0c\u9032\u4e00\u6b65\u63d0\u5347\u696d\u52d9\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728\u6578\u64da\u5eab\u4e2d\u66f4\u6539\u5217\u5c6c\u6027\uff0c\u5305\u62ec\u6578\u64da\u985e\u578b\u3001\u7d04\u675f\u548c\u9ed8\u8a8d\u503c\u7684\u4fee\u6539\u6b65\u9a5f\u8207\u6ce8\u610f\u4e8b\u9805\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-173421","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/173421","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=173421"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/173421\/revisions"}],"predecessor-version":[{"id":173422,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/173421\/revisions\/173422"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=173421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=173421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=173421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}