{"id":143829,"date":"2024-11-01T01:36:20","date_gmt":"2024-10-31T17:36:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/143829\/"},"modified":"2024-11-01T01:36:21","modified_gmt":"2024-10-31T17:36:21","slug":"sql-%e5%92%8c-oracle-%e7%9a%84%e7%b4%9a%e8%81%af%e5%88%aa%e9%99%a4","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/143829\/","title":{"rendered":"SQL \u548c ORACLE \u7684\u7d1a\u806f\u522a\u9664"},"content":{"rendered":"<h1 id=\"sql-%e5%92%8c-oracle-%e7%9a%84%e7%b4%9a%e8%81%af%e5%88%aa%e9%99%a4-NDrIVqVsvg\">SQL \u548c ORACLE \u7684\u7d1a\u806f\u522a\u9664<\/h1>\n<p>\u5728\u8cc7\u6599\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0c\u7d1a\u806f\u522a\u9664\u662f\u4e00\u500b\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u5177\u6709\u7236\u5b50\u95dc\u4fc2\u7684\u8cc7\u6599\u8868\u6642\u3002\u7576\u4e00\u500b\u7236\u8a18\u9304\u88ab\u522a\u9664\u6642\uff0c\u6240\u6709\u8207\u4e4b\u76f8\u95dc\u7684\u5b50\u8a18\u9304\u4e5f\u6703\u81ea\u52d5\u88ab\u522a\u9664\u3002\u9019\u7a2e\u64cd\u4f5c\u5728 SQL \u548c Oracle \u4e2d\u90fd\u6709\u5be6\u73fe\uff0c\u4f46\u5177\u9ad4\u7684\u8a9e\u6cd5\u548c\u884c\u70ba\u53ef\u80fd\u6703\u6709\u6240\u4e0d\u540c\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e7%b4%9a%e8%81%af%e5%88%aa%e9%99%a4%ef%bc%9f-NDrIVqVsvg\">\u4ec0\u9ebc\u662f\u7d1a\u806f\u522a\u9664\uff1f<\/h2>\n<p>\u7d1a\u806f\u522a\u9664\u662f\u6307\u5728\u8cc7\u6599\u5eab\u4e2d\uff0c\u7576\u4e00\u500b\u8a18\u9304\u88ab\u522a\u9664\u6642\uff0c\u6240\u6709\u8207\u8a72\u8a18\u9304\u6709\u95dc\u806f\u7684\u8a18\u9304\u4e5f\u6703\u81ea\u52d5\u88ab\u522a\u9664\u3002\u9019\u901a\u5e38\u7528\u65bc\u4e00\u5c0d\u591a\u7684\u95dc\u4fc2\u4e2d\uff0c\u4f8b\u5982\u4e00\u500b\u5ba2\u6236\u53ef\u4ee5\u6709\u591a\u500b\u8a02\u55ae\u3002\u5982\u679c\u5ba2\u6236\u88ab\u522a\u9664\uff0c\u5247\u6240\u6709\u8207\u8a72\u5ba2\u6236\u76f8\u95dc\u7684\u8a02\u55ae\u4e5f\u61c9\u8a72\u88ab\u522a\u9664\uff0c\u4ee5\u4fdd\u6301\u8cc7\u6599\u7684\u4e00\u81f4\u6027\u3002<\/p>\n<h2 id=\"sql-%e4%b8%ad%e7%9a%84%e7%b4%9a%e8%81%af%e5%88%aa%e9%99%a4-NDrIVqVsvg\">SQL \u4e2d\u7684\u7d1a\u806f\u522a\u9664<\/h2>\n<p>\u5728 SQL \u4e2d\uff0c\u7d1a\u806f\u522a\u9664\u901a\u5e38\u662f\u5728\u5efa\u7acb\u5916\u9375\u7d04\u675f\u6642\u6307\u5b9a\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7bc4\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5728 SQL \u4e2d\u8a2d\u7f6e\u7d1a\u806f\u522a\u9664\uff1a<\/p>\n<pre><code>CREATE TABLE Customers (\n    CustomerID int PRIMARY KEY,\n    CustomerName varchar(255)\n);\n\nCREATE TABLE Orders (\n    OrderID int PRIMARY KEY,\n    CustomerID int,\n    OrderDate date,\n    FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID) ON DELETE CASCADE\n);<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u7576\u4e00\u500b\u5ba2\u6236\u88ab\u522a\u9664\u6642\uff0c\u6240\u6709\u8207\u8a72\u5ba2\u6236\u76f8\u95dc\u7684\u8a02\u55ae\u4e5f\u6703\u81ea\u52d5\u88ab\u522a\u9664\u3002\u9019\u662f\u901a\u904e\u5728\u5916\u9375\u7d04\u675f\u4e2d\u4f7f\u7528 `ON DELETE CASCADE` \u4f86\u5be6\u73fe\u7684\u3002<\/p>\n<h2 id=\"oracle-%e4%b8%ad%e7%9a%84%e7%b4%9a%e8%81%af%e5%88%aa%e9%99%a4-NDrIVqVsvg\">Oracle \u4e2d\u7684\u7d1a\u806f\u522a\u9664<\/h2>\n<p>\u5728 Oracle \u4e2d\uff0c\u7d1a\u806f\u522a\u9664\u7684\u5be6\u73fe\u65b9\u5f0f\u8207 SQL \u985e\u4f3c\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u5728 Oracle \u4e2d\u8a2d\u7f6e\u7d1a\u806f\u522a\u9664\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>CREATE TABLE Customers (\n    CustomerID NUMBER PRIMARY KEY,\n    CustomerName VARCHAR2(255)\n);\n\nCREATE TABLE Orders (\n    OrderID NUMBER PRIMARY KEY,\n    CustomerID NUMBER,\n    OrderDate DATE,\n    CONSTRAINT fk_customer\n        FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID) ON DELETE CASCADE\n);<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c`ON DELETE CASCADE` \u7684\u4f7f\u7528\u65b9\u5f0f\u8207 SQL \u76f8\u540c\uff0c\u78ba\u4fdd\u4e86\u8cc7\u6599\u7684\u4e00\u81f4\u6027\u3002<\/p>\n<h2 id=\"%e7%b4%9a%e8%81%af%e5%88%aa%e9%99%a4%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-NDrIVqVsvg\">\u7d1a\u806f\u522a\u9664\u7684\u6ce8\u610f\u4e8b\u9805<\/h2>\n<ul>\n<li><strong>\u8cc7\u6599\u5b8c\u6574\u6027\uff1a<\/strong>\u7d1a\u806f\u522a\u9664\u53ef\u4ee5\u5e6b\u52a9\u7dad\u8b77\u8cc7\u6599\u7684\u5b8c\u6574\u6027\uff0c\u4f46\u4e5f\u53ef\u80fd\u5c0e\u81f4\u610f\u5916\u7684\u8cc7\u6599\u4e1f\u5931\u3002\u56e0\u6b64\uff0c\u5728\u4f7f\u7528\u7d1a\u806f\u522a\u9664\u6642\uff0c\u5fc5\u9808\u8b39\u614e\u8003\u616e\u3002<\/li>\n<li><strong>\u6027\u80fd\u5f71\u97ff\uff1a<\/strong>\u5728\u5927\u578b\u8cc7\u6599\u96c6\u4e0a\u57f7\u884c\u7d1a\u806f\u522a\u9664\u53ef\u80fd\u6703\u5f71\u97ff\u6027\u80fd\uff0c\u7279\u5225\u662f\u7576\u6709\u591a\u500b\u5c64\u7d1a\u7684\u95dc\u806f\u6642\u3002<\/li>\n<li><strong>\u6e2c\u8a66\u548c\u9a57\u8b49\uff1a<\/strong>\u5728\u751f\u7522\u74b0\u5883\u4e2d\u5be6\u65bd\u7d1a\u806f\u522a\u9664\u4e4b\u524d\uff0c\u61c9\u5728\u6e2c\u8a66\u74b0\u5883\u4e2d\u9032\u884c\u5145\u5206\u7684\u6e2c\u8a66\uff0c\u4ee5\u78ba\u4fdd\u4e0d\u6703\u610f\u5916\u522a\u9664\u91cd\u8981\u8cc7\u6599\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-NDrIVqVsvg\">\u7d50\u8ad6<\/h2>\n<p>\u7d1a\u806f\u522a\u9664\u662f\u4e00\u500b\u5f37\u5927\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u5e6b\u52a9\u7ba1\u7406\u8cc7\u6599\u5eab\u4e2d\u7684\u7236\u5b50\u95dc\u4fc2\uff0c\u78ba\u4fdd\u8cc7\u6599\u7684\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\u3002\u5728 SQL \u548c Oracle \u4e2d\uff0c\u901a\u904e\u8a2d\u7f6e\u5916\u9375\u7d04\u675f\u4f86\u5be6\u73fe\u7d1a\u806f\u522a\u9664\u662f\u76f8\u5c0d\u7c21\u55ae\u7684\u3002\u7136\u800c\uff0c\u4f7f\u7528\u6b64\u529f\u80fd\u6642\u5fc5\u9808\u8b39\u614e\uff0c\u4ee5\u907f\u514d\u610f\u5916\u522a\u9664\u91cd\u8981\u8cc7\u6599\u3002\u4e86\u89e3\u5982\u4f55\u6b63\u78ba\u4f7f\u7528\u7d1a\u806f\u522a\u9664\u5c07\u6709\u52a9\u65bc\u63d0\u9ad8\u8cc7\u6599\u5eab\u7ba1\u7406\u7684\u6548\u7387\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc\u8cc7\u6599\u5eab\u7ba1\u7406\u6216\u5176\u4ed6\u6280\u8853\u554f\u984c\u6709\u8208\u8da3\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4e86\u89e3\u66f4\u591a\u8cc7\u8a0a\uff0c\u7279\u5225\u662f\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u9069\u5408\u5404\u7a2e\u9700\u6c42\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u670d\u52d9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3 SQL \u548c ORACLE \u4e2d\u7684\u7d1a\u806f\u522a\u9664\uff0c\u638c\u63e1\u5982\u4f55\u81ea\u52d5\u522a\u9664\u76f8\u95dc\u6578\u64da\u4ee5\u7dad\u8b77\u6578\u64da\u5b8c\u6574\u6027\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-143829","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/143829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=143829"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/143829\/revisions"}],"predecessor-version":[{"id":143830,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/143829\/revisions\/143830"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=143829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=143829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=143829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}