{"id":5010,"date":"2024-11-14T09:35:28","date_gmt":"2024-11-14T01:35:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5010\/"},"modified":"2024-11-14T09:35:28","modified_gmt":"2024-11-14T01:35:28","slug":"oracle%e5%a4%96%e9%94%ae%e5%85%b3%e7%b3%bb%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5010\/","title":{"rendered":"oracle\u5916\u952e\u5173\u7cfb\u600e\u4e48\u8bbe\u7f6e"},"content":{"rendered":"<blockquote><p>\n  \u5728 oracle \u6570\u636e\u5e93\u4e2d\u8bbe\u7f6e\u5916\u952e\u5173\u7cfb\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a1. \u521b\u5efa\u5305\u542b\u5916\u952e\u5217\u7684\u8868\u30022. \u4f7f\u7528 alter table \u8bed\u53e5\u521b\u5efa\u5916\u952e\u7ea6\u675f\uff0c\u6307\u5b9a\u5916\u952e\u5217\u548c\u88ab\u5f15\u7528\u7684\u4e3b\u952e\u5217\u30023. \u68c0\u67e5\u7ea6\u675f\u662f\u5426\u5b58\u5728\u30024. \u4f7f\u7528 alter table \u8bed\u53e5\u542f\u7528\u7ea6\u675f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/21\/2024052110241845635.jpg\" class=\"aligncenter\" title=\"oracle\u5916\u952e\u5173\u7cfb\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" alt=\"oracle\u5916\u952e\u5173\u7cfb\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>Oracle \u5916\u952e\u5173\u7cfb\u8bbe\u7f6e<\/strong><\/p>\n<p><strong>\u5982\u4f55\u8bbe\u7f6e Oracle \u4e2d\u7684\u5916\u952e\u5173\u7cfb\uff1f<\/strong><\/p>\n<p>\u5728 Oracle \u6570\u636e\u5e93\u4e2d\u8bbe\u7f6e\u5916\u952e\u5173\u7cfb\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u8868<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u5305\u542b\u5916\u952e\u5217\u7684\u8868\u3002<\/li>\n<li>\u5916\u952e\u5217\u5fc5\u987b\u5f15\u7528\u53e6\u4e00\u5f20\u8868\u4e2d\u7684\u4e3b\u952e\u5217\u3002<\/li>\n<\/ul>\n<p><strong>2. \u521b\u5efa\u7ea6\u675f<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u521b\u5efa\u5916\u952e\u7ea6\u675f\u3002<\/li>\n<li>\u7ea6\u675f\u5305\u542b\u5916\u952e\u5217\u548c\u88ab\u5f15\u7528\u7684\u4e3b\u952e\u5217\u3002<\/li>\n<\/ul>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>ALTER TABLE child_table ADD FOREIGN KEY (fk_column) REFERENCES parent_table (pk_column);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>child_table \u662f\u5305\u542b\u5916\u952e\u5217\u7684\u8868\u3002<\/li>\n<li>fk_column \u662f\u5916\u952e\u5217\u3002<\/li>\n<li>parent_table \u662f\u88ab\u5f15\u7528\u7684\u8868\u3002<\/li>\n<li>pk_column \u662f\u4e3b\u952e\u5217\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>ALTER TABLE orders ADD FOREIGN KEY (customer_id) REFERENCES customers (customer_id);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u68c0\u67e5\u5916\u952e\u7ea6\u675f<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u68c0\u67e5\u5916\u952e\u7ea6\u675f\u662f\u5426\u5b58\u5728\u3002<\/li>\n<\/ul>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>ALTER TABLE child_table VALIDATE CONSTRAINT FOREIGN KEY (fk_column);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u542f\u7528\u5916\u952e\u7ea6\u675f<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u542f\u7528\u5916\u952e\u7ea6\u675f\u3002<\/li>\n<\/ul>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>ALTER TABLE child_table ENABLE CONSTRAINT FOREIGN KEY (fk_column);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>\u5916\u952e\u5217\u7684\u6570\u636e\u7c7b\u578b\u5fc5\u987b\u4e0e\u88ab\u5f15\u7528\u7684\u4e3b\u952e\u5217\u7684\u6570\u636e\u7c7b\u578b\u76f8\u540c\u3002<\/li>\n<li>\u53ef\u4ee5\u8bbe\u7f6e\u591a\u4e2a\u5916\u952e\u7ea6\u675f\u3002<\/li>\n<li>\u5916\u952e\u7ea6\u675f\u786e\u4fdd\u5b50\u8868\u4e2d\u7684\u6570\u636e\u4e0e\u7236\u8868\u4e2d\u7684\u6570\u636e\u4e00\u81f4\u6027\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5916\u952e\u5173\u7cfb\u600e\u4e48\u8bbe\u7f6e\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>\u5728 oracle \u6570\u636e\u5e93\u4e2d\u8bbe\u7f6e\u5916\u952e\u5173\u7cfb\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a1. \u521b\u5efa\u5305\u542b\u5916\u952e\u5217\u7684\u8868\u30022. \u4f7f\u7528 alter table \u8bed\u53e5\u521b\u5efa\u5916\u952e\u7ea6\u675f\uff0c\u6307\u5b9a\u5916\u952e\u5217\u548c\u88ab\u5f15\u7528\u7684\u4e3b\u952e\u5217\u30023. \u68c0\u67e5\u7ea6\u675f\u662f\u5426\u5b58\u5728\u30024. \u4f7f\u7528 alter table \u8bed\u53e5\u542f\u7528\u7ea6\u675f\u3002 Oracle \u5916\u952e\u5173\u7cfb\u8bbe\u7f6e \u5982\u4f55\u8bbe\u7f6e Oracle \u4e2d\u7684\u5916\u952e\u5173\u7cfb\uff1f \u5728 Oracle \u6570\u636e\u5e93\u4e2d\u8bbe\u7f6e\u5916\u952e\u5173\u7cfb\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u521b\u5efa\u8868 \u521b\u5efa\u5305\u542b\u5916\u952e\u5217\u7684\u8868\u3002 \u5916\u952e\u5217\u5fc5\u987b\u5f15\u7528\u53e6\u4e00\u5f20\u8868\u4e2d\u7684\u4e3b\u952e\u5217\u3002 2. \u521b\u5efa\u7ea6\u675f \u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u521b\u5efa\u5916\u952e\u7ea6\u675f\u3002 \u7ea6\u675f\u5305\u542b\u5916\u952e\u5217\u548c\u88ab\u5f15\u7528\u7684\u4e3b\u952e\u5217\u3002 \u8bed\u6cd5\uff1a ALTER TABLE child_table ADD FOREIGN KEY (fk_column) REFERENCES parent_table (pk_column); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a child_table \u662f\u5305\u542b\u5916\u952e\u5217\u7684\u8868\u3002 fk_column \u662f\u5916\u952e\u5217\u3002 parent_table \u662f\u88ab\u5f15\u7528\u7684\u8868\u3002 pk_column \u662f\u4e3b\u952e\u5217\u3002 \u793a\u4f8b\uff1a ALTER [&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-5010","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5010","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=5010"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5010\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}