{"id":5667,"date":"2024-11-14T09:48:05","date_gmt":"2024-11-14T01:48:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5667\/"},"modified":"2024-11-14T09:48:05","modified_gmt":"2024-11-14T01:48:05","slug":"sql%e8%af%ad%e5%8f%a5%e4%b8%8d%e7%ad%89%e4%ba%8e%e7%a9%ba%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5667\/","title":{"rendered":"sql\u8bed\u53e5\u4e0d\u7b49\u4e8e\u7a7a\u600e\u4e48\u5199"},"content":{"rendered":"<blockquote><p>\n  sql\u8bed\u53e5\u4e2d\u4f7f\u7528not null\u7ea6\u675f\u6765\u5224\u65ad\u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u3002\u521b\u5efa\u8868\u65f6\uff0c\u901a\u8fc7\u5728\u5b57\u6bb5\u58f0\u660e\u540e\u6dfb\u52a0not null\uff0c\u53ef\u786e\u4fdd\u8be5\u5b57\u6bb5\u5728\u63d2\u5165\u65f6\u4e0d\u4e3a\u7a7a\u3002\u67e5\u8be2\u65f6\uff0cwhere name is not null\u53ef\u7b5b\u9009\u51fa\u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u7684\u884c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/30\/2024053020155641810.jpg\" class=\"aligncenter\" title=\"sql\u8bed\u53e5\u4e0d\u7b49\u4e8e\u7a7a\u600e\u4e48\u5199\u63d2\u56fe\" alt=\"sql\u8bed\u53e5\u4e0d\u7b49\u4e8e\u7a7a\u600e\u4e48\u5199\u63d2\u56fe\" \/><\/p>\n<p><strong>SQL \u8bed\u53e5\u4e2d\u5224\u65ad\u5b57\u6bb5\u4e0d\u4e3a\u7a7a<\/strong><\/p>\n<p>\u5728 SQL \u8bed\u53e5\u4e2d\uff0c\u5224\u65ad\u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u53ef\u4ee5\u4f7f\u7528 NOT NULL \u7ea6\u675f\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>CREATE TABLE table_name (\n  column_name data_type NOT NULL,\n  ...\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f5c\u7528\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u5728\u5411\u8868\u4e2d\u63d2\u5165\u6570\u636e\u65f6\uff0ccolumn_name \u5b57\u6bb5\u4e0d\u80fd\u4e3a NULL\u3002<\/li>\n<li>\u5728\u67e5\u8be2\u6570\u636e\u65f6\uff0cNOT NULL \u7ea6\u675f\u53ef\u7528\u4e8e\u7b5b\u9009\u51fa column_name \u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u7684\u884c\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u5f20\u540d\u4e3a customers \u7684\u8868\uff0c\u5176\u4e2d name \u5b57\u6bb5\u4e0d\u5141\u8bb8\u4e3a NULL\uff1a<\/p>\n<pre>CREATE TABLE customers (\n  id INT PRIMARY KEY,\n  name VARCHAR(255) NOT NULL\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5411 customers \u8868\u63d2\u5165\u4e00\u6761\u6570\u636e\uff0c\u5176\u4e2d name \u5b57\u6bb5\u4e3a\u7a7a\uff1a<\/p>\n<pre>INSERT INTO customers (id, name) VALUES (1, NULL);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u64cd\u4f5c\u5c06\u56e0\u8fdd\u53cd NOT NULL \u7ea6\u675f\u800c\u5931\u8d25\u3002<\/p>\n<p>\u67e5\u8be2 customers \u8868\u4e2d name \u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u7684\u6240\u6709\u884c\uff1a<\/p>\n<pre>SELECT * FROM customers WHERE name IS NOT NULL;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u67e5\u8be2\u5c06\u8fd4\u56de name \u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u7684\u6240\u6709\u5ba2\u6237\u8bb0\u5f55\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e0d\u7b49\u4e8e\u7a7a\u600e\u4e48\u5199\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>sql\u8bed\u53e5\u4e2d\u4f7f\u7528not null\u7ea6\u675f\u6765\u5224\u65ad\u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u3002\u521b\u5efa\u8868\u65f6\uff0c\u901a\u8fc7\u5728\u5b57\u6bb5\u58f0\u660e\u540e\u6dfb\u52a0not null\uff0c\u53ef\u786e\u4fdd\u8be5\u5b57\u6bb5\u5728\u63d2\u5165\u65f6\u4e0d\u4e3a\u7a7a\u3002\u67e5\u8be2\u65f6\uff0cwhere name is not null\u53ef\u7b5b\u9009\u51fa\u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u7684\u884c\u3002 SQL \u8bed\u53e5\u4e2d\u5224\u65ad\u5b57\u6bb5\u4e0d\u4e3a\u7a7a \u5728 SQL \u8bed\u53e5\u4e2d\uff0c\u5224\u65ad\u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u53ef\u4ee5\u4f7f\u7528 NOT NULL \u7ea6\u675f\u3002 \u8bed\u6cd5\uff1a CREATE TABLE table_name ( column_name data_type NOT NULL, &#8230; ); \u767b\u5f55\u540e\u590d\u5236 \u4f5c\u7528\uff1a \u786e\u4fdd\u5728\u5411\u8868\u4e2d\u63d2\u5165\u6570\u636e\u65f6\uff0ccolumn_name \u5b57\u6bb5\u4e0d\u80fd\u4e3a NULL\u3002 \u5728\u67e5\u8be2\u6570\u636e\u65f6\uff0cNOT NULL \u7ea6\u675f\u53ef\u7528\u4e8e\u7b5b\u9009\u51fa column_name \u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u7684\u884c\u3002 \u793a\u4f8b\uff1a \u521b\u5efa\u4e00\u5f20\u540d\u4e3a customers \u7684\u8868\uff0c\u5176\u4e2d name \u5b57\u6bb5\u4e0d\u5141\u8bb8\u4e3a NULL\uff1a CREATE TABLE customers ( id INT PRIMARY KEY, name VARCHAR(255) NOT NULL [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5667","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5667"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5667\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}