{"id":20353,"date":"2024-01-02T04:46:18","date_gmt":"2024-01-02T04:46:18","guid":{"rendered":"https:\/\/server.hk\/blog\/20353\/"},"modified":"2024-11-14T10:39:55","modified_gmt":"2024-11-14T02:39:55","slug":"postgresql-command-drop-schema","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/20353\/","title":{"rendered":"PostgreSQL \u6307\u4ee4\uff1aDROP SCHEMA"},"content":{"rendered":"<h1 id=\"postgresql-command-drop-schema-dUUTTHytop\">PostgreSQL \u6307\u4ee4\uff1aDROP SCHEMA<\/h1>\n<p>PostgreSQL \u662f\u4e00\u500b\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u806f\u8cc7\u6599\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u5ee3\u6cdb\u7684\u529f\u80fd\u548c\u7279\u6027\u3002\u5728 PostgreSQL \u4e2d\uff0c\u4e00\u500b\u57fa\u672c\u7684\u6307\u4ee4\u662f DROP SCHEMA \u6307\u4ee4\uff0c\u8a72\u6307\u4ee4\u5141\u8a31\u7528\u6236\u5f9e\u8cc7\u6599\u5eab\u4e2d\u79fb\u9664\u4e00\u500b\u67b6\u69cb\u53ca\u5176\u6240\u6709\u76f8\u95dc\u5c0d\u8c61\u3002<\/p>\n<h2 id=\"understanding-schemas-in-postgresql-dUUTTHytop\">\u7406\u89e3 PostgreSQL \u4e2d\u7684\u67b6\u69cb<\/h2>\n<p>\u5728 PostgreSQL \u4e2d\uff0c\u67b6\u69cb\u662f\u4e00\u500b\u908f\u8f2f\u5bb9\u5668\uff0c\u5305\u542b\u8cc7\u6599\u5eab\u5c0d\u8c61\uff0c\u5982\u8868\u683c\u3001\u8996\u5716\u3001\u51fd\u6578\u548c\u5e8f\u5217\u3002\u67b6\u69cb\u63d0\u4f9b\u4e86\u4e00\u7a2e\u7d44\u7e54\u548c\u7ba1\u7406\u8cc7\u6599\u5eab\u5c0d\u8c61\u7684\u65b9\u6cd5\uff0c\u4f7f\u7528\u6236\u80fd\u5920\u5c07\u76f8\u95dc\u5c0d\u8c61\u5206\u7d44\u5728\u4e00\u8d77\u3002<\/p>\n<p>\u9ed8\u8a8d\u60c5\u6cc1\u4e0b\uff0c\u7576\u5275\u5efa\u4e00\u500b\u65b0\u7684\u8cc7\u6599\u5eab\u6642\uff0cPostgreSQL \u6703\u5275\u5efa\u4e00\u500b\u540d\u70ba &#8220;public&#8221; \u7684\u67b6\u69cb\u3002\u7136\u800c\uff0c\u7528\u6236\u53ef\u4ee5\u5275\u5efa\u984d\u5916\u7684\u67b6\u69cb\uff0c\u4ee5\u66f4\u6709\u6548\u5730\u7d44\u7e54\u4ed6\u5011\u7684\u8cc7\u6599\u5eab\u5c0d\u8c61\u3002<\/p>\n<h2 id=\"the-drop-schema-command-dUUTTHytop\">DROP SCHEMA \u6307\u4ee4<\/h2>\n<p>PostgreSQL \u4e2d\u7684 DROP SCHEMA \u6307\u4ee4\u5141\u8a31\u7528\u6236\u5f9e\u8cc7\u6599\u5eab\u4e2d\u79fb\u9664\u4e00\u500b\u67b6\u69cb\u53ca\u5176\u6240\u6709\u76f8\u95dc\u5c0d\u8c61\u3002DROP SCHEMA \u6307\u4ee4\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>DROP SCHEMA [IF EXISTS] schema_name [CASCADE | RESTRICT];\r\n<\/code><\/pre>\n<p><code>IF EXISTS<\/code> \u5b50\u53e5\u662f\u53ef\u9078\u7684\uff0c\u5982\u679c\u6307\u5b9a\u7684\u67b6\u69cb\u4e0d\u5b58\u5728\uff0c\u5247\u4e0d\u6703\u7522\u751f\u932f\u8aa4\u3002<code>CASCADE<\/code> \u95dc\u9375\u5b57\u7528\u65bc\u81ea\u52d5\u522a\u9664\u67b6\u69cb\u5167\u7684\u6240\u6709\u5c0d\u8c61\uff0c\u800c <code>RESTRICT<\/code> \u95dc\u9375\u5b57\u5247\u9632\u6b62\u522a\u9664\u5305\u542b\u4efb\u4f55\u5c0d\u8c61\u7684\u67b6\u69cb\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528 DROP SCHEMA \u6307\u4ee4\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>DROP SCHEMA sales CASCADE;\r\n<\/code><\/pre>\n<p>\u9019\u689d\u6307\u4ee4\u5c07\u522a\u9664 &#8220;sales&#8221; \u67b6\u69cb\u53ca\u5176\u6240\u6709\u76f8\u95dc\u5c0d\u8c61\uff0c\u5305\u62ec\u8868\u683c\u3001\u8996\u5716\u3001\u51fd\u6578\u548c\u5e8f\u5217\u3002<\/p>\n<h2 id=\"important-considerations-dUUTTHytop\">\u91cd\u8981\u8003\u616e\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528 DROP SCHEMA \u6307\u4ee4\u6642\uff0c\u5fc5\u9808\u8003\u616e\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u4e1f\u5931\uff1a<\/strong>\u522a\u9664\u67b6\u69cb\u5c07\u6c38\u4e45\u522a\u9664\u67b6\u69cb\u5167\u7684\u6240\u6709\u5c0d\u8c61\u3002\u5728\u57f7\u884c\u6307\u4ee4\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u5099\u4efd\u4efb\u4f55\u91cd\u8981\u6578\u64da\u3002<\/li>\n<li><strong>\u5c0d\u8c61\u4f9d\u8cf4\u6027\uff1a<\/strong>\u5982\u679c\u5176\u4ed6\u67b6\u69cb\u4e2d\u6709\u4efb\u4f55\u5c0d\u8c61\u4f9d\u8cf4\u65bc\u88ab\u522a\u9664\u67b6\u69cb\u4e2d\u7684\u5c0d\u8c61\uff0c\u5247 DROP SCHEMA \u6307\u4ee4\u5c07\u5931\u6557\u3002\u5728\u9019\u7a2e\u60c5\u6cc1\u4e0b\uff0c\u5fc5\u9808\u5148\u522a\u9664\u4f9d\u8cf4\u5c0d\u8c61\uff0c\u6216\u4f7f\u7528 CASCADE \u9078\u9805\u3002<\/li>\n<li><strong>\u6b0a\u9650\uff1a<\/strong>\u53ea\u6709\u67b6\u69cb\u7684\u64c1\u6709\u8005\u6216\u8d85\u7d1a\u7528\u6236\u624d\u80fd\u522a\u9664\u67b6\u69cb\u3002\u5728\u57f7\u884c\u6307\u4ee4\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u64c1\u6709\u5fc5\u8981\u7684\u6b0a\u9650\u3002<\/li>\n<\/ul>\n<h2 id=\"summary-dUUTTHytop\">\u7e3d\u7d50<\/h2>\n<p>PostgreSQL \u7684 DROP SCHEMA \u6307\u4ee4\u5141\u8a31\u7528\u6236\u5f9e\u8cc7\u6599\u5eab\u4e2d\u79fb\u9664\u4e00\u500b\u67b6\u69cb\u53ca\u5176\u6240\u6709\u76f8\u95dc\u5c0d\u8c61\u3002\u67b6\u69cb\u63d0\u4f9b\u4e86\u4e00\u7a2e\u6709\u6548\u7d44\u7e54\u548c\u7ba1\u7406\u8cc7\u6599\u5eab\u5c0d\u8c61\u7684\u65b9\u6cd5\u3002\u5728\u4f7f\u7528 DROP SCHEMA \u6307\u4ee4\u6642\uff0c\u5fc5\u9808\u8003\u616e\u6578\u64da\u4e1f\u5931\u3001\u5c0d\u8c61\u4f9d\u8cf4\u6027\u548c\u6b0a\u9650\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u6709\u95dc VPS \u4e3b\u6a5f\u548c PostgreSQL \u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8acb\u8003\u616e\u63a2\u7d22 <a href=\"https:\/\/server.hk\">Server.HK<\/a>\uff0c\u9019\u662f\u4e00\u5bb6\u9818\u5148\u7684 VPS \u4e3b\u6a5f\u63d0\u4f9b\u5546\uff0c\u63d0\u4f9b\u53ef\u9760\u548c\u9ad8\u6027\u80fd\u7684\u4e3b\u6a5f\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL \u6307\u4ee4\uff1aDR&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-20353","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20353","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=20353"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20353\/revisions"}],"predecessor-version":[{"id":24402,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20353\/revisions\/24402"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=20353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=20353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=20353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}