{"id":20344,"date":"2024-01-02T04:37:20","date_gmt":"2024-01-02T04:37:20","guid":{"rendered":"https:\/\/server.hk\/blog\/20344\/"},"modified":"2024-11-14T10:40:05","modified_gmt":"2024-11-14T02:40:05","slug":"postgresql-command-truncate-table","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/20344\/","title":{"rendered":"PostgreSQL \u6307\u4ee4\uff1aTRUNCATE TABLE"},"content":{"rendered":"<h1 id=\"postgresql-command-truncate-table-XlQHqQVDWo\">PostgreSQL \u6307\u4ee4\uff1aTRUNCATE TABLE<\/h1>\n<p>PostgreSQL \u662f\u4e00\u500b\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u806f\u5f0f\u8cc7\u6599\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u591a\u7a2e\u529f\u80fd\u53ca\u6307\u4ee4\u4f86\u7ba1\u7406\u548c\u64cd\u4f5c\u8cc7\u6599\u3002\u5176\u4e2d\u4e00\u500b\u91cd\u8981\u7684\u6307\u4ee4\u662f <strong>TRUNCATE TABLE<\/strong>\uff0c\u5b83\u5141\u8a31\u60a8\u5feb\u901f\u9ad8\u6548\u5730\u522a\u9664\u8cc7\u6599\u8868\u4e2d\u7684\u6240\u6709\u8cc7\u6599\u3002\u672c\u6587\u5c07\u63a2\u8a0e PostgreSQL \u4e2d <code>TRUNCATE TABLE<\/code> \u6307\u4ee4\u7684\u8a9e\u6cd5\u3001\u7528\u9014\u53ca\u5176\u512a\u9ede\u3002<\/p>\n<h2 id=\"syntax-XlQHqQVDWo\">\u8a9e\u6cd5<\/h2>\n<p><code>TRUNCATE TABLE<\/code> \u6307\u4ee4\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>TRUNCATE TABLE table_name;<\/code><\/pre>\n<p>\u5728\u6b64\uff0c<code>table_name<\/code> \u6307\u7684\u662f\u60a8\u60f3\u8981\u79fb\u9664\u6240\u6709\u8cc7\u6599\u7684\u8cc7\u6599\u8868\u540d\u7a31\u3002<\/p>\n<h2 id=\"usage-XlQHqQVDWo\">\u7528\u9014<\/h2>\n<p><code>TRUNCATE TABLE<\/code> \u6307\u4ee4\u901a\u5e38\u7528\u65bc\u9700\u8981\u522a\u9664\u8cc7\u6599\u8868\u4e2d\u6240\u6709\u8cc7\u6599\u800c\u4e0d\u522a\u9664\u8cc7\u6599\u8868\u7d50\u69cb\u7684\u5834\u666f\u3002\u8207 <code>DELETE<\/code> \u6307\u4ee4\u76f8\u6bd4\uff0c<code>TRUNCATE TABLE<\/code> \u5c0d\u65bc\u5927\u8cc7\u6599\u8868\u7684\u8655\u7406\u901f\u5ea6\u66f4\u5feb\u4e14\u66f4\u9ad8\u6548\u3002<\/p>\n<p>\u7576\u60a8\u57f7\u884c <code>TRUNCATE TABLE<\/code> \u6307\u4ee4\u6642\uff0cPostgreSQL \u6703\u79fb\u9664\u6307\u5b9a\u8cc7\u6599\u8868\u4e2d\u7684\u6240\u6709\u8cc7\u6599\u5217\uff0c\u4e26\u91cb\u653e\u9019\u4e9b\u8cc7\u6599\u5217\u4f54\u7528\u7684\u78c1\u789f\u7a7a\u9593\u3002\u4e0d\u904e\uff0c\u5b83\u4e0d\u6703\u751f\u6210\u4efb\u4f55\u64a4\u92b7\u65e5\u8a8c\u6216\u5c07\u8cc7\u6599\u5beb\u5165\u4ea4\u6613\u65e5\u8a8c\uff0c\u56e0\u6b64\u9019\u662f\u4e00\u500b\u975e\u4ea4\u6613\u64cd\u4f5c\u3002\u9019\u610f\u5473\u8457\u60a8\u7121\u6cd5\u56de\u6efe <code>TRUNCATE TABLE<\/code> \u6307\u4ee4\u7684\u6548\u679c\u3002<\/p>\n<p>\u6b64\u5916\uff0c<code>TRUNCATE TABLE<\/code> \u6703\u5c07\u76f8\u95dc\u7684\u5e8f\u5217\u7269\u4ef6\u91cd\u7f6e\u81f3\u5176\u521d\u59cb\u503c\uff0c\u6709\u6548\u5730\u91cd\u65b0\u555f\u52d5\u5e8f\u5217\u3002\u7576\u60a8\u60f3\u8981\u91cd\u7f6e\u81ea\u52d5\u905e\u589e\u7684\u4e3b\u9375\u6216\u5176\u4ed6\u57fa\u65bc\u5e8f\u5217\u7684\u6b04\u4f4d\u6642\uff0c\u9019\u7a2e\u884c\u70ba\u975e\u5e38\u6709\u7528\u3002<\/p>\n<h2 id=\"example-XlQHqQVDWo\">\u7bc4\u4f8b<\/h2>\n<p>\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u540d\u70ba <code>customers<\/code> \u7684\u8cc7\u6599\u8868\uff0c\u7528\u4f86\u5132\u5b58\u5ba2\u6236\u7684\u76f8\u95dc\u8cc7\u8a0a\u3002\u82e5\u8981\u4f7f\u7528 <code>TRUNCATE TABLE<\/code> \u6307\u4ee4\u522a\u9664\u6b64\u8cc7\u6599\u8868\u4e2d\u7684\u6240\u6709\u8cc7\u6599\uff0c\u60a8\u53ef\u4ee5\u57f7\u884c\u4ee5\u4e0b SQL \u8a9e\u53e5\uff1a<\/p>\n<pre><code>TRUNCATE TABLE customers;<\/code><\/pre>\n<p>\u57f7\u884c\u6b64\u6307\u4ee4\u5f8c\uff0c<code>customers<\/code> \u8cc7\u6599\u8868\u5c07\u8b8a\u70ba\u7a7a\u8868\uff0c\u4e14\u6240\u6709\u76f8\u95dc\u7684\u5e8f\u5217\u7269\u4ef6\u5c07\u88ab\u91cd\u7f6e\u3002<\/p>\n<h2 id=\"benefits-XlQHqQVDWo\">\u512a\u9ede<\/h2>\n<p><code>TRUNCATE TABLE<\/code> \u6307\u4ee4\u76f8\u6bd4\u65bc\u50b3\u7d71\u7684 <code>DELETE<\/code> \u6307\u4ee4\uff0c\u63d0\u4f9b\u4e86\u5e7e\u500b\u986f\u8457\u7684\u512a\u9ede\uff1a<\/p>\n<ul>\n<li><strong>\u901f\u5ea6\uff1a<\/strong> <code>TRUNCATE TABLE<\/code> \u5c0d\u65bc\u5927\u8cc7\u6599\u8868\u4f86\u8aaa\u6bd4 <code>DELETE<\/code> \u66f4\u5feb\uff0c\u56e0\u70ba\u5b83\u4e0d\u6703\u751f\u6210\u64a4\u92b7\u65e5\u8a8c\u6216\u5beb\u5165\u4ea4\u6613\u65e5\u8a8c\u3002<\/li>\n<li><strong>\u6548\u7387\uff1a<\/strong> \u901a\u904e\u91cb\u653e\u78c1\u789f\u7a7a\u9593\u4e26\u91cd\u7f6e\u5e8f\u5217\u7269\u4ef6\uff0c<code>TRUNCATE TABLE<\/code> \u6709\u52a9\u65bc\u512a\u5316\u8cc7\u6599\u5eab\u6548\u80fd\u548c\u5b58\u5132\u5229\u7528\u7387\u3002<\/li>\n<li><strong>\u7c21\u55ae\u6027\uff1a<\/strong> <code>TRUNCATE TABLE<\/code> \u7684\u8a9e\u6cd5\u7c21\u55ae\u6613\u61c2\uff0c\u4f7f\u5176\u6210\u70ba\u79fb\u9664\u8cc7\u6599\u8868\u4e2d\u6240\u6709\u8cc7\u6599\u7684\u4fbf\u5229\u9078\u64c7\u3002<\/li>\n<\/ul>\n<h2 id=\"summary-XlQHqQVDWo\">\u7e3d\u7d50<\/h2>\n<p>PostgreSQL \u4e2d\u7684 <code>TRUNCATE TABLE<\/code> \u6307\u4ee4\u63d0\u4f9b\u4e86\u4e00\u7a2e\u5feb\u901f\u9ad8\u6548\u7684\u65b9\u5f0f\u4f86\u522a\u9664\u8cc7\u6599\u8868\u4e2d\u7684\u6240\u6709\u8cc7\u6599\uff0c\u540c\u6642\u4fdd\u7559\u8cc7\u6599\u8868\u7d50\u69cb\u3002\u5b83\u5728\u8655\u7406\u5927\u8cc7\u6599\u8868\u6642\u7279\u5225\u6709\u7528\uff0c\u4e26\u63d0\u4f9b\u4e86\u901f\u5ea6\u3001\u6548\u7387\u548c\u7c21\u55ae\u6027\u7b49\u512a\u9ede\u3002\u5982\u9700\u4e86\u89e3\u66f4\u591a\u95dc\u65bc PostgreSQL \u7684\u529f\u80fd\uff0c\u53ef\u8003\u616e\u63a2\u7d22 <a href=\"https:\/\/server.hk\">Server.HK<\/a>\uff0c\u9019\u662f\u4e00\u5bb6\u9818\u5148\u7684 VPS \u8a17\u7ba1\u516c\u53f8\uff0c\u63d0\u4f9b\u53ef\u9760\u4e14\u5177\u53ef\u64f4\u5c55\u6027\u7684\u8a17\u7ba1\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL \u6307\u4ee4\uff1aTR&#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-20344","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20344","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=20344"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20344\/revisions"}],"predecessor-version":[{"id":24415,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20344\/revisions\/24415"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=20344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=20344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=20344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}