{"id":5037,"date":"2024-11-14T08:46:20","date_gmt":"2024-11-14T00:46:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5037\/"},"modified":"2024-11-14T08:46:20","modified_gmt":"2024-11-14T00:46:20","slug":"oracle%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae%e4%b8%bb%e9%94%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5037\/","title":{"rendered":"oracle\u600e\u4e48\u8bbe\u7f6e\u4e3b\u952e"},"content":{"rendered":"<blockquote><p>\n  \u4f7f\u7528 oracle \u8bbe\u7f6e\u4e3b\u952e\u53ef\u4ee5\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u3002\u9996\u5148\u786e\u5b9a\u4e00\u4e2a\u6216\u591a\u4e2a\u552f\u4e00\u6807\u8bc6\u6bcf\u884c\u7684\u5217\uff0c\u7136\u540e\u4f7f\u7528 alter table \u547d\u4ee4\u521b\u5efa\u4e3b\u952e\u7ea6\u675f\uff0c\u4f8b\u5982\uff1aalter table customers add primary key (customer_id);\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/21\/2024052112091769805.jpg\" class=\"aligncenter\" title=\"oracle\u600e\u4e48\u8bbe\u7f6e\u4e3b\u952e\u63d2\u56fe\" alt=\"oracle\u600e\u4e48\u8bbe\u7f6e\u4e3b\u952e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Oracle \u8bbe\u7f6e\u4e3b\u952e<\/strong><\/p>\n<p>\u5728 Oracle \u6570\u636e\u5e93\u4e2d\uff0c\u4e3b\u952e\u7528\u4e8e\u552f\u4e00\u6807\u8bc6\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u3002\u8bbe\u7f6e\u4e3b\u952e\u53ef\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u6570\u636e\u4e00\u81f4\u6027\u3002<\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><strong>1. \u786e\u5b9a\u4e3b\u952e\u5217<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u786e\u5b9a\u8868\u4e2d\u7528\u4e8e\u552f\u4e00\u6807\u8bc6\u6bcf\u884c\u7684\u5217\u6216\u5217\u7ec4\u5408\u3002\u4e3b\u952e\u5217\u901a\u5e38\u4e3a\u975e\u7a7a\u4e14\u552f\u4e00\u7684\u3002<\/p>\n<p><strong>2. \u521b\u5efa\u4e3b\u952e\u7ea6\u675f<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u5728\u8868\u4e0a\u521b\u5efa\u4e3b\u952e\u7ea6\u675f\uff1a<\/p>\n<pre>ALTER TABLE table_name ADD PRIMARY KEY (column1, column2, ...);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>table_name \u662f\u8981\u521b\u5efa\u4e3b\u952e\u7ea6\u675f\u7684\u8868\u7684\u540d\u79f0\u3002<\/li>\n<li>column1, column2, &#8230; \u662f\u7ec4\u6210\u4e3b\u952e\u7684\u5217\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a customers \u7684\u8868\uff0c\u5176\u4e2d customer_id \u5217\u552f\u4e00\u6807\u8bc6\u6bcf\u4f4d\u5ba2\u6237\u3002\u8981\u8bbe\u7f6e customer_id \u5217\u4e3a\u4e3b\u952e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>ALTER TABLE customers ADD PRIMARY KEY (customer_id);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u4e3b\u952e\u53ea\u80fd\u5728\u5355\u4e2a\u8868\u4e0a\u521b\u5efa\uff0c\u4e0d\u80fd\u8de8\u591a\u4e2a\u8868\u3002<\/li>\n<li>\u4e3b\u952e\u5217\u4e0d\u80fd\u4e3a NULL\u3002<\/li>\n<li>\u53ef\u4ee5\u540c\u65f6\u8bbe\u7f6e\u591a\u4e2a\u5217\u4e3a\u4e3b\u952e\uff08\u590d\u5408\u4e3b\u952e\uff09\u3002<\/li>\n<li>\u5982\u679c\u5c1d\u8bd5\u63d2\u5165\u5177\u6709\u91cd\u590d\u4e3b\u952e\u503c\u7684\u884c\uff0cOracle \u5c06\u5f15\u53d1\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u8bbe\u7f6e\u4e3b\u952e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 oracle \u8bbe\u7f6e\u4e3b\u952e\u53ef\u4ee5\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u3002\u9996\u5148\u786e\u5b9a\u4e00\u4e2a\u6216\u591a\u4e2a\u552f\u4e00\u6807\u8bc6\u6bcf\u884c\u7684\u5217\uff0c\u7136\u540e\u4f7f\u7528 alter table \u547d\u4ee4\u521b\u5efa\u4e3b\u952e\u7ea6\u675f\uff0c\u4f8b\u5982\uff1aalter table customers add primary key (customer_id); \u5982\u4f55\u4f7f\u7528 Oracle \u8bbe\u7f6e\u4e3b\u952e \u5728 Oracle \u6570\u636e\u5e93\u4e2d\uff0c\u4e3b\u952e\u7528\u4e8e\u552f\u4e00\u6807\u8bc6\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u3002\u8bbe\u7f6e\u4e3b\u952e\u53ef\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u6570\u636e\u4e00\u81f4\u6027\u3002 \u6b65\u9aa4\uff1a 1. \u786e\u5b9a\u4e3b\u952e\u5217 \u9996\u5148\uff0c\u786e\u5b9a\u8868\u4e2d\u7528\u4e8e\u552f\u4e00\u6807\u8bc6\u6bcf\u884c\u7684\u5217\u6216\u5217\u7ec4\u5408\u3002\u4e3b\u952e\u5217\u901a\u5e38\u4e3a\u975e\u7a7a\u4e14\u552f\u4e00\u7684\u3002 2. \u521b\u5efa\u4e3b\u952e\u7ea6\u675f \u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u5728\u8868\u4e0a\u521b\u5efa\u4e3b\u952e\u7ea6\u675f\uff1a ALTER TABLE table_name ADD PRIMARY KEY (column1, column2, &#8230;); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a table_name \u662f\u8981\u521b\u5efa\u4e3b\u952e\u7ea6\u675f\u7684\u8868\u7684\u540d\u79f0\u3002 column1, column2, &#8230; \u662f\u7ec4\u6210\u4e3b\u952e\u7684\u5217\u3002 \u793a\u4f8b\uff1a \u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a customers \u7684\u8868\uff0c\u5176\u4e2d customer_id \u5217\u552f\u4e00\u6807\u8bc6\u6bcf\u4f4d\u5ba2\u6237\u3002\u8981\u8bbe\u7f6e customer_id \u5217\u4e3a\u4e3b\u952e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a ALTER TABLE customers ADD PRIMARY [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5037","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5037"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5037\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}