{"id":5048,"date":"2024-11-14T08:44:11","date_gmt":"2024-11-14T00:44:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5048\/"},"modified":"2024-11-14T08:44:11","modified_gmt":"2024-11-14T00:44:11","slug":"oracle%e6%80%8e%e4%b9%88%e6%b7%bb%e5%8a%a0%e4%b8%bb%e9%94%ae%e7%ba%a6%e6%9d%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5048\/","title":{"rendered":"oracle\u600e\u4e48\u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f"},"content":{"rendered":"<blockquote><p>\n  \u4e3b\u952e\u7ea6\u675f\u7528\u4e8e\u6807\u8bc6\u8868\u683c\u4e2d\u6bcf\u4e00\u884c\uff1a\u5b9a\u4e49\u552f\u4e00\u4e14\u975e\u7a7a\u7684\u5217\u4e3a\u4e3b\u952e\u5217\u3002\u5728\u521b\u5efa\u8868\u65f6\u4f7f\u7528 create table \u8bed\u53e5\u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f\uff0c\u6216\u4f7f\u7528 alter table \u8bed\u53e5\u5411\u73b0\u6709\u8868\u4e2d\u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f\u3002oracle \u652f\u6301\u590d\u5408\u4e3b\u952e\uff0c\u5176\u4e2d\u591a\u4e2a\u5217\u8054\u5408\u4f5c\u4e3a\u4e3b\u952e\u3002\u4e3b\u952e\u7ea6\u675f\u53ef\u63d0\u9ad8\u6570\u636e\u5e93\u6027\u80fd\uff0c\u56e0\u4e3a\u5b83\u53ef\u5feb\u901f\u67e5\u627e\u548c\u68c0\u7d22\u6570\u636e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/21\/2024052112511951188.jpg\" class=\"aligncenter\" title=\"oracle\u600e\u4e48\u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f\u63d2\u56fe\" alt=\"oracle\u600e\u4e48\u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Oracle \u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f<\/strong><\/p>\n<p>\u4e3b\u952e\u7ea6\u675f\u662f\u4e00\u79cd\u6570\u636e\u5e93\u5b8c\u6574\u6027\u7ea6\u675f\uff0c\u7528\u4e8e\u552f\u4e00\u6807\u8bc6\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u3002\u5728 Oracle \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f\uff1a<\/p>\n<p><strong>1. \u5b9a\u4e49\u4e3b\u952e\u5217<\/strong><br \/>\u9996\u5148\uff0c\u786e\u5b9a\u8981\u4f5c\u4e3a\u4e3b\u952e\u7684\u5217\u3002\u4e3b\u952e\u5217\u7684\u503c\u5e94\u8be5\u662f\u552f\u4e00\u7684\uff0c\u5e76\u4e14\u4e0d\u80fd\u4e3a null\u3002<\/p>\n<p><strong>2. \u4f7f\u7528 CREATE TABLE \u8bed\u53e5<\/strong><br \/>\u5728\u521b\u5efa\u8868\u65f6\uff0c\u4f7f\u7528 CREATE TABLE \u8bed\u53e5\u5c06\u4e3b\u952e\u7ea6\u675f\u6dfb\u52a0\u5230\u8868\u4e2d\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>CREATE TABLE table_name (\n  column_name data_type PRIMARY KEY\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>CREATE TABLE employees (\n  id NUMBER PRIMARY KEY,\n  name VARCHAR2(255),\n  email VARCHAR2(255)\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cid \u5217\u88ab\u5b9a\u4e49\u4e3a\u4e3b\u952e\u3002<\/p>\n<p><strong>3. \u4f7f\u7528 ALTER TABLE \u8bed\u53e5<\/strong><br \/>\u8981\u5411\u73b0\u6709\u8868\u4e2d\u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f\uff0c\u53ef\u4ee5\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>ALTER TABLE table_name ADD PRIMARY KEY (column_name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>ALTER TABLE customers ADD PRIMARY KEY (customer_id);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u590d\u5408\u4e3b\u952e<\/strong><br \/>Oracle \u8fd8\u652f\u6301\u590d\u5408\u4e3b\u952e\uff0c\u5176\u4e2d\u591a\u4e2a\u5217\u8054\u5408\u8d77\u6765\u4f5c\u4e3a\u4e3b\u952e\u3002\u8981\u521b\u5efa\u590d\u5408\u4e3b\u952e\uff0c\u8bf7\u5728 PRIMARY KEY \u7ea6\u675f\u4e2d\u6307\u5b9a\u591a\u4e2a\u5217\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>CREATE TABLE table_name (\n  column_name1 data_type,\n  column_name2 data_type,\n  PRIMARY KEY (column_name1, column_name2)\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u4e3b\u952e\u7ea6\u675f\u53ea\u5141\u8bb8\u552f\u4e00\u4e14\u975e\u7a7a\u7684\u503c\u3002<\/li>\n<li>\u4e00\u65e6\u6dfb\u52a0\u4e86\u4e3b\u952e\u7ea6\u675f\uff0c\u5c31\u4e0d\u80fd\u66f4\u6539\u6216\u5220\u9664\u4e3b\u952e\u5217\u3002<\/li>\n<li>\u5982\u679c\u5c1d\u8bd5\u63d2\u5165\u6216\u66f4\u65b0\u8fdd\u53cd\u4e3b\u952e\u7ea6\u675f\u7684\u884c\uff0c\u5219\u4f1a\u4ea7\u751f\u9519\u8bef\u3002<\/li>\n<li>\u4e3b\u952e\u7ea6\u675f\u53ef\u4ee5\u63d0\u9ad8\u6570\u636e\u5e93\u6027\u80fd\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u5feb\u901f\u67e5\u627e\u548c\u68c0\u7d22\u6570\u636e\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f\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>\u4e3b\u952e\u7ea6\u675f\u7528\u4e8e\u6807\u8bc6\u8868\u683c\u4e2d\u6bcf\u4e00\u884c\uff1a\u5b9a\u4e49\u552f\u4e00\u4e14\u975e\u7a7a\u7684\u5217\u4e3a\u4e3b\u952e\u5217\u3002\u5728\u521b\u5efa\u8868\u65f6\u4f7f\u7528 create table \u8bed\u53e5\u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f\uff0c\u6216\u4f7f\u7528 alter table \u8bed\u53e5\u5411\u73b0\u6709\u8868\u4e2d\u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f\u3002oracle \u652f\u6301\u590d\u5408\u4e3b\u952e\uff0c\u5176\u4e2d\u591a\u4e2a\u5217\u8054\u5408\u4f5c\u4e3a\u4e3b\u952e\u3002\u4e3b\u952e\u7ea6\u675f\u53ef\u63d0\u9ad8\u6570\u636e\u5e93\u6027\u80fd\uff0c\u56e0\u4e3a\u5b83\u53ef\u5feb\u901f\u67e5\u627e\u548c\u68c0\u7d22\u6570\u636e\u3002 \u5982\u4f55\u4f7f\u7528 Oracle \u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f \u4e3b\u952e\u7ea6\u675f\u662f\u4e00\u79cd\u6570\u636e\u5e93\u5b8c\u6574\u6027\u7ea6\u675f\uff0c\u7528\u4e8e\u552f\u4e00\u6807\u8bc6\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u3002\u5728 Oracle \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6dfb\u52a0\u4e3b\u952e\u7ea6\u675f\uff1a 1. \u5b9a\u4e49\u4e3b\u952e\u5217\u9996\u5148\uff0c\u786e\u5b9a\u8981\u4f5c\u4e3a\u4e3b\u952e\u7684\u5217\u3002\u4e3b\u952e\u5217\u7684\u503c\u5e94\u8be5\u662f\u552f\u4e00\u7684\uff0c\u5e76\u4e14\u4e0d\u80fd\u4e3a null\u3002 2. \u4f7f\u7528 CREATE TABLE \u8bed\u53e5\u5728\u521b\u5efa\u8868\u65f6\uff0c\u4f7f\u7528 CREATE TABLE \u8bed\u53e5\u5c06\u4e3b\u952e\u7ea6\u675f\u6dfb\u52a0\u5230\u8868\u4e2d\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a CREATE TABLE table_name ( column_name data_type PRIMARY KEY ); \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff1a CREATE TABLE employees ( id NUMBER PRIMARY KEY, name VARCHAR2(255), email VARCHAR2(255) ); \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cid \u5217\u88ab\u5b9a\u4e49\u4e3a\u4e3b\u952e\u3002 3. \u4f7f\u7528 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-5048","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5048","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=5048"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5048\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}