{"id":5040,"date":"2024-11-14T13:00:57","date_gmt":"2024-11-14T05:00:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5040\/"},"modified":"2024-11-14T13:00:57","modified_gmt":"2024-11-14T05:00:57","slug":"oracle%e4%b8%bb%e9%94%ae%e6%80%8e%e4%b9%88%e6%94%b9","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5040\/","title":{"rendered":"oracle\u4e3b\u952e\u600e\u4e48\u6539"},"content":{"rendered":"<blockquote><p>\n  oracle \u4e2d\u4fee\u6539\u4e3b\u952e\u7684\u6b65\u9aa4\u4e3a\uff1a\u521b\u5efa\u65b0\u4e3b\u952e\uff1b\u5220\u9664\u73b0\u6709\u4e3b\u952e\uff1b\u6dfb\u52a0\u5916\u952e\u7ea6\u675f\uff08\u53ef\u9009\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/21\/2024052112211725478.jpg\" class=\"aligncenter\" title=\"oracle\u4e3b\u952e\u600e\u4e48\u6539\u63d2\u56fe\" alt=\"oracle\u4e3b\u952e\u600e\u4e48\u6539\u63d2\u56fe\" \/><\/p>\n<p><strong>Oracle \u4e2d\u4fee\u6539\u4e3b\u952e\u7684\u6b65\u9aa4<\/strong><\/p>\n<p>\u5728 Oracle \u6570\u636e\u5e93\u4e2d\u4fee\u6539\u4e3b\u952e\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u65b0\u4e3b\u952e<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u521b\u5efa\u65b0\u4e3b\u952e\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/li>\n<\/ul>\n<pre>ALTER TABLE table_name ADD PRIMARY KEY (column_name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u5176\u4e2d table_name \u662f\u8981\u66f4\u6539\u7684\u4e3b\u952e\u7684\u8868\u540d\uff0c\u800c column_name \u662f\u8981\u4f5c\u4e3a\u65b0\u4e3b\u952e\u7684\u5217\u3002<\/li>\n<\/ul>\n<p><strong>2. \u5220\u9664\u73b0\u6709\u4e3b\u952e<\/strong><\/p>\n<ul>\n<li>\u4e00\u65e6\u521b\u5efa\u4e86\u65b0\u4e3b\u952e\uff0c\u5c31\u53ef\u4ee5\u5220\u9664\u73b0\u6709\u4e3b\u952e\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/li>\n<\/ul>\n<pre>ALTER TABLE table_name DROP PRIMARY KEY;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u6dfb\u52a0\u5916\u952e\u7ea6\u675f\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u8be5\u8868\u53c2\u4e0e\u4e86\u4efb\u4f55\u5916\u952e\u5173\u7cfb\uff0c\u5219\u9700\u8981\u6dfb\u52a0\u5916\u952e\u7ea6\u675f\u4ee5\u786e\u4fdd\u8868\u4e4b\u95f4\u7684\u5173\u7cfb\u4ecd\u7136\u6709\u6548\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/li>\n<\/ul>\n<pre>ALTER TABLE table_name ADD FOREIGN KEY (column_name) REFERENCES other_table(column_name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u5176\u4e2d table_name \u662f\u7236\u8868\uff0cother_table \u662f\u5b50\u8868\uff0ccolumn_name \u662f\u7236\u8868\u548c\u5b50\u8868\u4e2d\u8981\u8fde\u63a5\u7684\u5217\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a students \u7684\u8868\uff0c\u5b83\u5177\u6709\u4e3b\u952e student_id\u3002\u8981\u5c06\u4e3b\u952e\u66f4\u6539\u4e3a\u5217 name\uff0c\u8bf7\u6309\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u521b\u5efa\u65b0\u4e3b\u952e\uff1a<\/li>\n<\/ol>\n<pre>ALTER TABLE students ADD PRIMARY KEY (name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u5220\u9664\u73b0\u6709\u4e3b\u952e\uff1a<\/li>\n<\/ol>\n<pre>ALTER TABLE students DROP PRIMARY KEY;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u6dfb\u52a0\u5916\u952e\u7ea6\u675f\uff08\u5982\u679c\u9700\u8981\uff09\uff1a<\/li>\n<\/ol>\n<pre>ALTER TABLE grades ADD FOREIGN KEY (student_name) REFERENCES students(name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u6309\u7167\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u6210\u529f\u5730\u5728 Oracle \u6570\u636e\u5e93\u4e2d\u4fee\u6539\u4e3b\u952e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e3b\u952e\u600e\u4e48\u6539\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>oracle \u4e2d\u4fee\u6539\u4e3b\u952e\u7684\u6b65\u9aa4\u4e3a\uff1a\u521b\u5efa\u65b0\u4e3b\u952e\uff1b\u5220\u9664\u73b0\u6709\u4e3b\u952e\uff1b\u6dfb\u52a0\u5916\u952e\u7ea6\u675f\uff08\u53ef\u9009\uff09\u3002 Oracle \u4e2d\u4fee\u6539\u4e3b\u952e\u7684\u6b65\u9aa4 \u5728 Oracle \u6570\u636e\u5e93\u4e2d\u4fee\u6539\u4e3b\u952e\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u521b\u5efa\u65b0\u4e3b\u952e \u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u521b\u5efa\u65b0\u4e3b\u952e\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a ALTER TABLE table_name ADD PRIMARY KEY (column_name); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d table_name \u662f\u8981\u66f4\u6539\u7684\u4e3b\u952e\u7684\u8868\u540d\uff0c\u800c column_name \u662f\u8981\u4f5c\u4e3a\u65b0\u4e3b\u952e\u7684\u5217\u3002 2. \u5220\u9664\u73b0\u6709\u4e3b\u952e \u4e00\u65e6\u521b\u5efa\u4e86\u65b0\u4e3b\u952e\uff0c\u5c31\u53ef\u4ee5\u5220\u9664\u73b0\u6709\u4e3b\u952e\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a ALTER TABLE table_name DROP PRIMARY KEY; \u767b\u5f55\u540e\u590d\u5236 3. \u6dfb\u52a0\u5916\u952e\u7ea6\u675f\uff08\u53ef\u9009\uff09 \u5982\u679c\u8be5\u8868\u53c2\u4e0e\u4e86\u4efb\u4f55\u5916\u952e\u5173\u7cfb\uff0c\u5219\u9700\u8981\u6dfb\u52a0\u5916\u952e\u7ea6\u675f\u4ee5\u786e\u4fdd\u8868\u4e4b\u95f4\u7684\u5173\u7cfb\u4ecd\u7136\u6709\u6548\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a ALTER TABLE table_name ADD FOREIGN KEY (column_name) REFERENCES other_table(column_name); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d table_name \u662f\u7236\u8868\uff0cother_table \u662f\u5b50\u8868\uff0ccolumn_name \u662f\u7236\u8868\u548c\u5b50\u8868\u4e2d\u8981\u8fde\u63a5\u7684\u5217\u3002 \u793a\u4f8b\uff1a [&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-5040","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5040","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=5040"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5040\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}