{"id":179818,"date":"2024-11-09T05:03:17","date_gmt":"2024-11-08T21:03:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/179818\/"},"modified":"2024-11-09T05:03:18","modified_gmt":"2024-11-08T21:03:18","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e5%84%b2%e5%ad%98%e5%b8%83%e7%88%be%e9%a1%9e%e5%9e%8b%e6%95%b8%e6%93%9a%ef%bc%9f-%e6%95%b8%e6%93%9a%e5%ba%ab%e6%80%8e%e9%ba%bc%e5%ad%98","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/179818\/","title":{"rendered":"\u5982\u4f55\u5728\u6578\u64da\u5eab\u4e2d\u5132\u5b58\u5e03\u723e\u985e\u578b\u6578\u64da\uff1f (\u6578\u64da\u5eab\u600e\u9ebc\u5b58\u5132 boolean)"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e5%84%b2%e5%ad%98%e5%b8%83%e7%88%be%e9%a1%9e%e5%9e%8b%e6%95%b8%e6%93%9a%ef%bc%9f-enXFgsnYwH\">\u5982\u4f55\u5728\u6578\u64da\u5eab\u4e2d\u5132\u5b58\u5e03\u723e\u985e\u578b\u6578\u64da\uff1f<\/h1>\n<p>\u5728\u73fe\u4ee3\u61c9\u7528\u7a0b\u5e8f\u958b\u767c\u4e2d\uff0c\u5e03\u723e\u985e\u578b\u6578\u64da\uff08Boolean\uff09\u662f\u4e00\u7a2e\u5e38\u898b\u7684\u6578\u64da\u985e\u578b\uff0c\u901a\u5e38\u7528\u65bc\u8868\u793a\u771f\uff08True\uff09\u6216\u5047\uff08False\uff09\u7684\u72c0\u614b\u3002\u9019\u7a2e\u6578\u64da\u985e\u578b\u5728\u6578\u64da\u5eab\u4e2d\u5132\u5b58\u6642\uff0c\u96d6\u7136\u770b\u4f3c\u7c21\u55ae\uff0c\u4f46\u5be6\u969b\u4e0a\u6709\u591a\u7a2e\u65b9\u6cd5\u53ef\u4ee5\u5be6\u73fe\uff0c\u4e26\u4e14\u4e0d\u540c\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u5c0d\u5e03\u723e\u985e\u578b\u7684\u652f\u6301\u548c\u5be6\u73fe\u65b9\u5f0f\u4e5f\u6709\u6240\u4e0d\u540c\u3002<\/p>\n<h2 id=\"%e5%b8%83%e7%88%be%e9%a1%9e%e5%9e%8b%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-enXFgsnYwH\">\u5e03\u723e\u985e\u578b\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u5e03\u723e\u985e\u578b\u6578\u64da\u901a\u5e38\u7528\u65bc\u8868\u793a\u4e8c\u5143\u9078\u64c7\uff0c\u4f8b\u5982\u7528\u6236\u662f\u5426\u555f\u7528\u67d0\u500b\u529f\u80fd\u3001\u8a02\u55ae\u662f\u5426\u5df2\u5b8c\u6210\u7b49\u3002\u5728\u6578\u64da\u5eab\u4e2d\uff0c\u5e03\u723e\u503c\u901a\u5e38\u4ee5\u5169\u7a2e\u5f62\u5f0f\u5b58\u5132\uff1a\u6574\u6578\uff080\u548c1\uff09\u6216\u5c08\u7528\u7684\u5e03\u723e\u985e\u578b\u3002<\/p>\n<h2 id=\"%e4%b8%8d%e5%90%8c%e6%95%b8%e6%93%9a%e5%ba%ab%e7%b3%bb%e7%b5%b1%e4%b8%ad%e7%9a%84%e5%b8%83%e7%88%be%e9%a1%9e%e5%9e%8b-enXFgsnYwH\">\u4e0d\u540c\u6578\u64da\u5eab\u7cfb\u7d71\u4e2d\u7684\u5e03\u723e\u985e\u578b<\/h2>\n<h3 id=\"1-mysql-enXFgsnYwH\">1. MySQL<\/h3>\n<p>\u5728MySQL\u4e2d\uff0c\u5e03\u723e\u985e\u578b\u5be6\u969b\u4e0a\u662fTINYINT(1)\u3002\u9019\u610f\u5473\u8457\u4f60\u53ef\u4ee5\u4f7f\u75280\u8868\u793a\u5047\uff08False\uff09\uff0c\u4f7f\u75281\u8868\u793a\u771f\uff08True\uff09\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u4e00\u500b\u5305\u542b\u5e03\u723e\u985e\u578b\u5b57\u6bb5\u7684\u8868\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>CREATE TABLE users (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    username VARCHAR(50) NOT NULL,\n    is_active TINYINT(1) NOT NULL DEFAULT 1\n);<\/code><\/pre>\n<h3 id=\"2-postgresql-enXFgsnYwH\">2. PostgreSQL<\/h3>\n<p>PostgreSQL\u63d0\u4f9b\u4e86\u539f\u751f\u7684\u5e03\u723e\u985e\u578b\uff0c\u4f7f\u7528BOOLEAN\u4f86\u5b9a\u7fa9\u3002\u9019\u4f7f\u5f97\u5728\u67e5\u8a62\u548c\u64cd\u4f5c\u6642\u66f4\u52a0\u76f4\u89c0\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u4e00\u500b\u5305\u542b\u5e03\u723e\u985e\u578b\u5b57\u6bb5\u7684\u8868\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>CREATE TABLE users (\n    id SERIAL PRIMARY KEY,\n    username VARCHAR(50) NOT NULL,\n    is_active BOOLEAN NOT NULL DEFAULT TRUE\n);<\/code><\/pre>\n<h3 id=\"3-sql-server-enXFgsnYwH\">3. SQL Server<\/h3>\n<p>\u5728SQL Server\u4e2d\uff0c\u5e03\u723e\u985e\u578b\u901a\u5e38\u4f7f\u7528BIT\u4f86\u8868\u793a\u3002BIT\u985e\u578b\u53ef\u4ee5\u5b58\u51320\u30011\u6216NULL\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u4e00\u500b\u5305\u542b\u5e03\u723e\u985e\u578b\u5b57\u6bb5\u7684\u8868\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>CREATE TABLE users (\n    id INT IDENTITY(1,1) PRIMARY KEY,\n    username NVARCHAR(50) NOT NULL,\n    is_active BIT NOT NULL DEFAULT 1\n);<\/code><\/pre>\n<h3 id=\"4-sqlite-enXFgsnYwH\">4. SQLite<\/h3>\n<p>SQLite\u4e26\u6c92\u6709\u5c08\u9580\u7684\u5e03\u723e\u985e\u578b\uff0c\u4f46\u53ef\u4ee5\u4f7f\u7528\u6574\u6578\u4f86\u8868\u793a\u3002\u901a\u5e38\u4f7f\u75280\u8868\u793a\u5047\uff08False\uff09\uff0c1\u8868\u793a\u771f\uff08True\uff09\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u4e00\u500b\u5305\u542b\u5e03\u723e\u985e\u578b\u5b57\u6bb5\u7684\u8868\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>CREATE TABLE users (\n    id INTEGER PRIMARY KEY AUTOINCREMENT,\n    username TEXT NOT NULL,\n    is_active INTEGER NOT NULL DEFAULT 1\n);<\/code><\/pre>\n<h2 id=\"%e5%b8%83%e7%88%be%e9%a1%9e%e5%9e%8b%e7%9a%84%e4%bd%bf%e7%94%a8%e5%bb%ba%e8%ad%b0-enXFgsnYwH\">\u5e03\u723e\u985e\u578b\u7684\u4f7f\u7528\u5efa\u8b70<\/h2>\n<ul>\n<li><strong>\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u985e\u578b\uff1a<\/strong>\u6839\u64da\u6240\u4f7f\u7528\u7684\u6578\u64da\u5eab\u7cfb\u7d71\uff0c\u9078\u64c7\u5408\u9069\u7684\u5e03\u723e\u985e\u578b\u4f86\u78ba\u4fdd\u6578\u64da\u7684\u6e96\u78ba\u6027\u548c\u53ef\u8b80\u6027\u3002<\/li>\n<li><strong>\u4f7f\u7528\u9ed8\u8a8d\u503c\uff1a<\/strong>\u5728\u5275\u5efa\u8868\u6642\uff0c\u70ba\u5e03\u723e\u985e\u578b\u5b57\u6bb5\u8a2d\u7f6e\u5408\u7406\u7684\u9ed8\u8a8d\u503c\uff0c\u4ee5\u907f\u514d\u5728\u63d2\u5165\u6578\u64da\u6642\u51fa\u73fe\u4e0d\u5fc5\u8981\u7684\u932f\u8aa4\u3002<\/li>\n<li><strong>\u6ce8\u610fNULL\u503c\uff1a<\/strong>\u67d0\u4e9b\u6578\u64da\u5eab\u7cfb\u7d71\u5141\u8a31\u5e03\u723e\u985e\u578b\u5b57\u6bb5\u70baNULL\uff0c\u9019\u53ef\u80fd\u6703\u5f71\u97ff\u67e5\u8a62\u7d50\u679c\uff0c\u56e0\u6b64\u5728\u8a2d\u8a08\u6578\u64da\u5eab\u6642\u9700\u8b39\u614e\u8003\u616e\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-enXFgsnYwH\">\u7d50\u8ad6<\/h2>\n<p>\u5e03\u723e\u985e\u578b\u6578\u64da\u5728\u6578\u64da\u5eab\u4e2d\u7684\u5132\u5b58\u65b9\u5f0f\u56e0\u6578\u64da\u5eab\u7cfb\u7d71\u800c\u7570\u3002\u4e86\u89e3\u5404\u7a2e\u6578\u64da\u5eab\u7684\u7279\u6027\u548c\u6700\u4f73\u5be6\u8e10\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u6709\u6548\u5730\u8a2d\u8a08\u548c\u7ba1\u7406\u6578\u64da\u5eab\u3002\u7121\u8ad6\u662f\u4f7f\u7528\u6574\u6578\u9084\u662f\u5c08\u7528\u7684\u5e03\u723e\u985e\u578b\uff0c\u9078\u64c7\u5408\u9069\u7684\u5b58\u5132\u65b9\u5f0f\u90fd\u80fd\u63d0\u9ad8\u6578\u64da\u7684\u53ef\u8b80\u6027\u548c\u64cd\u4f5c\u7684\u4fbf\u5229\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\u61c9\u7528\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728\u6578\u64da\u5eab\u4e2d\u6709\u6548\u5132\u5b58\u5e03\u723e\u985e\u578b\u6578\u64da\uff0c\u5305\u62ec\u4f7f\u7528\u6574\u6578\u3001\u4f4d\u5143\u7d44\u6216\u5c08\u7528\u5e03\u723e\u985e\u578b\u7684\u6700\u4f73\u5be6\u8e10\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-179818","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179818","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=179818"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179818\/revisions"}],"predecessor-version":[{"id":179819,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179818\/revisions\/179819"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=179818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=179818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=179818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}