{"id":6091,"date":"2024-11-14T11:08:54","date_gmt":"2024-11-14T03:08:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6091\/"},"modified":"2024-11-14T11:08:54","modified_gmt":"2024-11-14T03:08:54","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8oracle%e4%b8%ad%e5%88%9b%e5%bb%ba%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6091\/","title":{"rendered":"\u5982\u4f55\u5728oracle\u4e2d\u521b\u5efa\u8868"},"content":{"rendered":"<blockquote><p>\n  \u521b\u5efa oracle \u8868\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u4f7f\u7528 create table \u8bed\u6cd5\u6307\u5b9a\u8868\u540d\u3001\u5217\u540d\u3001\u6570\u636e\u7c7b\u578b\u3001\u7ea6\u675f\u548c\u9ed8\u8ba4\u503c\u3002\u8868\u540d\u5e94\u7b80\u6d01\u3001\u63cf\u8ff0\u6027\uff0c\u4e14\u4e0d\u8d85\u8fc7 30 \u4e2a\u5b57\u7b26\u3002\u5217\u540d\u5e94\u63cf\u8ff0\u6027\uff0c\u6570\u636e\u7c7b\u578b\u6307\u5b9a\u5217\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\u3002not null \u7ea6\u675f\u786e\u4fdd\u5217\u4e2d\u4e0d\u5141\u8bb8\u4f7f\u7528\u7a7a\u503c\uff0cdefault \u5b50\u53e5\u53ef\u6307\u5b9a\u5217\u7684\u9ed8\u8ba4\u503c\u3002primary key \u7ea6\u675f\u6807\u8bc6\u8868\u7684\u552f\u4e00\u8bb0\u5f55\u3002foreign key \u7ea6\u675f\u6307\u5b9a\u8868\u4e2d\u7684\u5217\u5f15\u7528\u53e6\u4e00\u4e2a\u8868\u4e2d\u7684\u4e3b\u952e\u3002\u8bf7\u53c2\u89c1\u793a\u4f8b\u8868 students \u7684\u521b\u5efa\uff0c\u5176\u4e2d\u5305\u542b\u4e3b\u952e\u3001\u552f\u4e00\u7ea6\u675f\u548c\u9ed8\u8ba4\u503c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/12\/2024061222332491746.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728oracle\u4e2d\u521b\u5efa\u8868\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728oracle\u4e2d\u521b\u5efa\u8868\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Oracle \u4e2d\u521b\u5efa\u8868<\/strong><\/p>\n<p>Oracle \u4e2d\u521b\u5efa\u8868\u662f\u4e00\u4e2a\u57fa\u672c\u800c\u91cd\u8981\u7684\u64cd\u4f5c\uff0c\u7528\u4e8e\u5b58\u50a8\u548c\u7ba1\u7406\u6570\u636e\u3002\u521b\u5efa\u8868\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u8868\u8bed\u6cd5<\/strong><\/p>\n<pre>CREATE TABLE table_name (\n  column_name data_type [NOT NULL] [DEFAULT default_value],\n  ...\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u8868\u540d<\/strong><\/p>\n<p>\u8868\u540d\u5e94\u7b80\u6d01\u3001\u63cf\u8ff0\u6027\uff0c\u5e76\u4e14\u4e0d\u5f97\u8d85\u8fc7 30 \u4e2a\u5b57\u7b26\u3002\u8868\u540d\u5e94\u4ee5\u5b57\u6bcd\u5f00\u5934\uff0c\u5e76\u4ec5\u5305\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\u3002<\/p>\n<p><strong>3. \u5217\u540d\u548c\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<p>\u5217\u540d\u5e94\u63cf\u8ff0\u6027\uff0c\u5e76\u9075\u5faa\u4e0e\u8868\u540d\u76f8\u540c\u7684\u547d\u540d\u7ea6\u5b9a\u3002\u6570\u636e\u7c7b\u578b\u6307\u5b9a\u5217\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\u3002\u5e38\u89c1\u7684\u7c7b\u578b\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u6570\u5b57\uff08NUMBER\uff09<\/li>\n<li>\u5b57\u7b26\u4e32\uff08VARCHAR2\uff09<\/li>\n<li>\u65e5\u671f\uff08DATE\uff09<\/li>\n<li>\u65f6\u95f4\uff08TIMESTAMP\uff09<\/li>\n<\/ul>\n<p><strong>4. \u53ef\u7a7a\u6027\u548c\u9ed8\u8ba4\u503c<\/strong><\/p>\n<p>NOT NULL \u7ea6\u675f\u53ef\u786e\u4fdd\u5217\u4e2d\u4e0d\u5141\u8bb8\u4f7f\u7528\u7a7a\u503c\u3002DEFAULT \u5b50\u53e5\u53ef\u6307\u5b9a\u5217\u7684\u9ed8\u8ba4\u503c\uff0c\u5728\u63d2\u5165\u65f6\u4f7f\u7528\u3002<\/p>\n<p><strong>5. \u4e3b\u952e\u7ea6\u675f<\/strong><\/p>\n<p>\u4e3b\u952e\u7ea6\u675f\u6807\u8bc6\u8868\u7684\u552f\u4e00\u8bb0\u5f55\u3002\u4f7f\u7528 PRIMARY KEY \u7ea6\u675f\u6307\u5b9a\u4e00\u4e2a\u6216\u591a\u4e2a\u5217\u4f5c\u4e3a\u4e3b\u952e\uff1a<\/p>\n<pre>PRIMARY KEY (column_name, ...);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u5916\u952e\u7ea6\u675f<\/strong><\/p>\n<p>\u5916\u952e\u7ea6\u675f\u6307\u5b9a\u8868\u4e2d\u7684\u5217\u5f15\u7528\u53e6\u4e00\u4e2a\u8868\u4e2d\u7684\u4e3b\u952e\u3002\u8fd9\u786e\u4fdd\u4e86\u8868\u4e4b\u95f4\u7684\u6570\u636e\u5b8c\u6574\u6027\uff1a<\/p>\n<pre>FOREIGN KEY (column_name) REFERENCES other_table(primary_key_column);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>7. \u793a\u4f8b<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a students \u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4ee5\u4e0b\u5217\uff1a<\/p>\n<pre>CREATE TABLE students (\n  id NUMBER PRIMARY KEY,\n  name VARCHAR2(50) NOT NULL,\n  age NUMBER,\n  email VARCHAR2(100) UNIQUE,\n  gpa NUMBER(3,2) DEFAULT 0.00\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8bf7\u6ce8\u610f\uff0cid \u5217\u662f\u4e3b\u952e\uff0cemail \u5217\u662f\u552f\u4e00\u7ea6\u675f\uff0c\u5e76\u4e14 gpa \u5217\u5177\u6709\u9ed8\u8ba4\u503c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728\u4e2d\u521b\u5efa\u8868\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>\u521b\u5efa oracle \u8868\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u4f7f\u7528 create table \u8bed\u6cd5\u6307\u5b9a\u8868\u540d\u3001\u5217\u540d\u3001\u6570\u636e\u7c7b\u578b\u3001\u7ea6\u675f\u548c\u9ed8\u8ba4\u503c\u3002\u8868\u540d\u5e94\u7b80\u6d01\u3001\u63cf\u8ff0\u6027\uff0c\u4e14\u4e0d\u8d85\u8fc7 30 \u4e2a\u5b57\u7b26\u3002\u5217\u540d\u5e94\u63cf\u8ff0\u6027\uff0c\u6570\u636e\u7c7b\u578b\u6307\u5b9a\u5217\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\u3002not null \u7ea6\u675f\u786e\u4fdd\u5217\u4e2d\u4e0d\u5141\u8bb8\u4f7f\u7528\u7a7a\u503c\uff0cdefault \u5b50\u53e5\u53ef\u6307\u5b9a\u5217\u7684\u9ed8\u8ba4\u503c\u3002primary key \u7ea6\u675f\u6807\u8bc6\u8868\u7684\u552f\u4e00\u8bb0\u5f55\u3002foreign key \u7ea6\u675f\u6307\u5b9a\u8868\u4e2d\u7684\u5217\u5f15\u7528\u53e6\u4e00\u4e2a\u8868\u4e2d\u7684\u4e3b\u952e\u3002\u8bf7\u53c2\u89c1\u793a\u4f8b\u8868 students \u7684\u521b\u5efa\uff0c\u5176\u4e2d\u5305\u542b\u4e3b\u952e\u3001\u552f\u4e00\u7ea6\u675f\u548c\u9ed8\u8ba4\u503c\u3002 \u5982\u4f55\u5728 Oracle \u4e2d\u521b\u5efa\u8868 Oracle \u4e2d\u521b\u5efa\u8868\u662f\u4e00\u4e2a\u57fa\u672c\u800c\u91cd\u8981\u7684\u64cd\u4f5c\uff0c\u7528\u4e8e\u5b58\u50a8\u548c\u7ba1\u7406\u6570\u636e\u3002\u521b\u5efa\u8868\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u521b\u5efa\u8868\u8bed\u6cd5 CREATE TABLE table_name ( column_name data_type [NOT NULL] [DEFAULT default_value], &#8230; ); \u767b\u5f55\u540e\u590d\u5236 2. \u8868\u540d \u8868\u540d\u5e94\u7b80\u6d01\u3001\u63cf\u8ff0\u6027\uff0c\u5e76\u4e14\u4e0d\u5f97\u8d85\u8fc7 30 \u4e2a\u5b57\u7b26\u3002\u8868\u540d\u5e94\u4ee5\u5b57\u6bcd\u5f00\u5934\uff0c\u5e76\u4ec5\u5305\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\u3002 3. \u5217\u540d\u548c\u6570\u636e\u7c7b\u578b \u5217\u540d\u5e94\u63cf\u8ff0\u6027\uff0c\u5e76\u9075\u5faa\u4e0e\u8868\u540d\u76f8\u540c\u7684\u547d\u540d\u7ea6\u5b9a\u3002\u6570\u636e\u7c7b\u578b\u6307\u5b9a\u5217\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\u3002\u5e38\u89c1\u7684\u7c7b\u578b\u5305\u62ec\uff1a \u6570\u5b57\uff08NUMBER\uff09 \u5b57\u7b26\u4e32\uff08VARCHAR2\uff09 \u65e5\u671f\uff08DATE\uff09 \u65f6\u95f4\uff08TIMESTAMP\uff09 4. \u53ef\u7a7a\u6027\u548c\u9ed8\u8ba4\u503c NOT NULL \u7ea6\u675f\u53ef\u786e\u4fdd\u5217\u4e2d\u4e0d\u5141\u8bb8\u4f7f\u7528\u7a7a\u503c\u3002DEFAULT \u5b50\u53e5\u53ef\u6307\u5b9a\u5217\u7684\u9ed8\u8ba4\u503c\uff0c\u5728\u63d2\u5165\u65f6\u4f7f\u7528\u3002 [&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-6091","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6091","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=6091"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6091\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}