{"id":20350,"date":"2024-01-02T04:43:21","date_gmt":"2024-01-02T04:43:21","guid":{"rendered":"https:\/\/server.hk\/blog\/20350\/"},"modified":"2024-11-14T10:39:58","modified_gmt":"2024-11-14T02:39:58","slug":"postgresql-command-drop-sequence","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/20350\/","title":{"rendered":"PostgreSQL \u6307\u4ee4\uff1aDROP SEQUENCE"},"content":{"rendered":"<h1 id=\"postgresql-command-drop-sequence-BvQBjypZTA\">PostgreSQL \u6307\u4ee4\uff1aDROP SEQUENCE<\/h1>\n<p>\u5728 PostgreSQL \u4e2d\uff0c<code>DROP SEQUENCE<\/code> \u6307\u4ee4\u7528\u65bc\u5f9e\u8cc7\u6599\u5eab\u4e2d\u522a\u9664\u4e00\u500b\u5e8f\u5217\u3002\u5e8f\u5217\u662f\u4e00\u500b\u751f\u6210\u552f\u4e00\u7de8\u865f\u7684\u5c0d\u8c61\uff0c\u901a\u5e38\u7528\u65bc\u751f\u6210\u8cc7\u6599\u8868\u7684\u4e3b\u9375\u503c\u3002<\/p>\n<h2 id=\"syntax-BvQBjypZTA\">\u8a9e\u6cd5<\/h2>\n<p><code>DROP SEQUENCE<\/code> \u6307\u4ee4\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>DROP SEQUENCE [IF EXISTS] sequence_name [CASCADE | RESTRICT];\r\n<\/code><\/pre>\n<p>\u8b93\u6211\u5011\u4f86\u5206\u89e3\u9019\u500b\u8a9e\u6cd5\uff1a<\/p>\n<ul>\n<li><code>IF EXISTS<\/code>\uff08\u53ef\u9078\uff09\uff1a\u6b64\u5b50\u53e5\u5141\u8a31\u60a8\u5728\u5e8f\u5217\u4e0d\u5b58\u5728\u6642\u907f\u514d\u51fa\u932f\u3002<\/li>\n<li><code>sequence_name<\/code>\uff1a\u6307\u5b9a\u8981\u522a\u9664\u7684\u5e8f\u5217\u540d\u7a31\u3002<\/li>\n<li><code>CASCADE | RESTRICT<\/code>\uff08\u53ef\u9078\uff09\uff1a\u9019\u5169\u500b\u9078\u9805\u7528\u65bc\u8655\u7406\u76f8\u95dc\u7684\u4f9d\u8cf4\u5c0d\u8c61\u3002<code>CASCADE<\/code> \u8868\u793a\u5982\u679c\u5b58\u5728\u4f9d\u8cf4\u5c0d\u8c61\uff08\u5982\u4f7f\u7528\u6b64\u5e8f\u5217\u7684\u6b04\u4f4d\uff09\uff0c\u5247\u6703\u4e00\u4f75\u522a\u9664\u6240\u6709\u76f8\u95dc\u5c0d\u8c61\uff1b<code>RESTRICT<\/code> \u5247\u6703\u5728\u6709\u4f9d\u8cf4\u5c0d\u8c61\u6642\u4f7f\u6307\u4ee4\u57f7\u884c\u5931\u6557\u3002<\/li>\n<\/ul>\n<h2 id=\"examples-BvQBjypZTA\">\u7bc4\u4f8b<\/h2>\n<p>\u8b93\u6211\u5011\u901a\u904e\u4e00\u4e9b\u7bc4\u4f8b\u4f86\u7406\u89e3 <code>DROP SEQUENCE<\/code> \u6307\u4ee4\u7684\u904b\u4f5c\u65b9\u5f0f\u3002<\/p>\n<h3 id=\"example-1-basic-usage-BvQBjypZTA\">\u7bc4\u4f8b 1\uff1a\u57fa\u672c\u4f7f\u7528<\/h3>\n<p>\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u540d\u70ba <code>customer_id_seq<\/code> \u7684\u5e8f\u5217\uff0c\u6211\u5011\u5e0c\u671b\u5c07\u5176\u5f9e\u8cc7\u6599\u5eab\u4e2d\u79fb\u9664\u3002\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6307\u4ee4\uff1a<\/p>\n<pre><code>DROP SEQUENCE customer_id_seq;\r\n<\/code><\/pre>\n<p>\u9019\u689d\u6307\u4ee4\u5c07\u6703\u5f9e\u8cc7\u6599\u5eab\u4e2d\u522a\u9664 <code>customer_id_seq<\/code> \u5e8f\u5217\u3002<\/p>\n<h3 id=\"example-2-handling-dependent-objects-BvQBjypZTA\">\u7bc4\u4f8b 2\uff1a\u8655\u7406\u4f9d\u8cf4\u5c0d\u8c61<\/h3>\n<p>\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u540d\u70ba <code>customers<\/code> \u7684\u8cc7\u6599\u8868\uff0c\u5176\u4e2d\u7684\u6b04\u4f4d <code>customer_id<\/code> \u4f7f\u7528\u4e86 <code>customer_id_seq<\/code> \u5e8f\u5217\u3002\u5982\u679c\u6211\u5011\u5728\u6c92\u6709\u8655\u7406\u4f9d\u8cf4\u5c0d\u8c61\u7684\u60c5\u6cc1\u4e0b\u5617\u8a66\u522a\u9664\u8a72\u5e8f\u5217\uff0c\u6703\u51fa\u73fe\u4ee5\u4e0b\u932f\u8aa4\uff1a<\/p>\n<pre><code>ERROR: cannot drop sequence customer_id_seq because other objects depend on it\r\nDETAIL: default for table customers column customer_id depends on sequence customer_id_seq\r\nHINT: Use DROP ... CASCADE to drop the dependent objects too.\r\n<\/code><\/pre>\n<p>\u82e5\u8981\u9023\u540c\u5176\u4f9d\u8cf4\u5c0d\u8c61\u4e00\u8d77\u522a\u9664\u8a72\u5e8f\u5217\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 <code>CASCADE<\/code> \u9078\u9805\uff1a<\/p>\n<pre><code>DROP SEQUENCE customer_id_seq CASCADE;\r\n<\/code><\/pre>\n<p>\u6b64\u6307\u4ee4\u5c07\u6703\u522a\u9664 <code>customer_id_seq<\/code> \u5e8f\u5217\u53ca\u5176\u4f9d\u8cf4\u5c0d\u8c61\uff0c\u5982 <code>customers<\/code> \u8cc7\u6599\u8868\u53ca\u76f8\u95dc\u6b04\u4f4d\u3002<\/p>\n<h2 id=\"summary-BvQBjypZTA\">\u7e3d\u7d50<\/h2>\n<p>PostgreSQL \u4e2d\u7684 <code>DROP SEQUENCE<\/code> \u6307\u4ee4\u5141\u8a31\u60a8\u5f9e\u8cc7\u6599\u5eab\u4e2d\u522a\u9664\u4e00\u500b\u5e8f\u5217\u3002\u5b83\u5177\u6709\u7c21\u55ae\u7684\u8a9e\u6cd5\uff0c\u60a8\u53ea\u9700\u6307\u5b9a\u8981\u522a\u9664\u7684\u5e8f\u5217\u540d\u7a31\u3002\u4f7f\u7528 <code>CASCADE<\/code> \u6216 <code>RESTRICT<\/code> \u9078\u9805\uff0c\u60a8\u53ef\u4ee5\u8655\u7406\u76f8\u95dc\u7684\u4f9d\u8cf4\u5c0d\u8c61\u3002\u4e86\u89e3\u5982\u4f55\u6b63\u78ba\u4f7f\u7528\u6b64\u6307\u4ee4\u5c0d\u65bc\u6709\u6548\u7ba1\u7406 PostgreSQL \u4e2d\u7684\u5e8f\u5217\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<p>\u5982\u9700\u66f4\u591a\u6709\u95dc VPS \u8a17\u7ba1\u670d\u52d9\u7684\u4fe1\u606f\uff0c\u8acb\u8003\u616e\u67e5\u770b <a href=\"https:\/\/server.hk\">Server.HK<\/a>\uff0c\u4ed6\u5011\u63d0\u4f9b\u53ef\u9760\u4e14\u9ad8\u6548\u7684 VPS \u89e3\u6c7a\u65b9\u6848\uff0c\u6eff\u8db3\u60a8\u7684\u8a17\u7ba1\u9700\u6c42\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-20350","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20350","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=20350"}],"version-history":[{"count":2,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20350\/revisions"}],"predecessor-version":[{"id":24407,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20350\/revisions\/24407"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=20350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=20350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=20350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}