{"id":354,"date":"2016-12-11T21:30:47","date_gmt":"2016-12-11T13:30:47","guid":{"rendered":"https:\/\/blog.freesilo.com\/?p=354"},"modified":"2016-12-11T21:30:47","modified_gmt":"2016-12-11T13:30:47","slug":"mysql%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%92%8c%e5%b8%b8%e7%94%a8%e5%ad%97%e6%ae%b5%e5%b1%9e%e6%80%a7%e6%80%bb%e7%bb%93-%e5%ad%97%e6%ae%b5%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/freesilo.com\/?p=354","title":{"rendered":"MySQL\u6570\u636e\u7c7b\u578b\u548c\u5e38\u7528\u5b57\u6bb5\u5c5e\u6027\u603b\u7ed3 &#8212; \u5b57\u6bb5\u7c7b\u578b"},"content":{"rendered":"<p><strong>\u524d\u8a00<\/strong><\/p>\n<p>\u597d\u6bd4C++\u4e2d\uff0c\u5b9a\u4e49int\u7c7b\u578b\u9700\u8981\u591a\u5c11\u5b57\u8282\uff0c\u5b9a\u4e49double\u7c7b\u578b\u9700\u8981\u591a\u5c11\u5b57\u8282\u4e00\u6837\uff0cMySQL\u5bf9\u8868\u6bcf\u4e2a\u5217\u4e2d\u7684\u6570\u636e\u4e5f\u4f1a\u5b9e\u884c\u4e25\u683c\u63a7\u5236\uff0c\u8fd9\u662f\u6570\u636e\u9a71\u52a8\u5e94\u7528\u7a0b\u5e8f\u6210\u529f\u7684\u5173\u952e\u3002M\u524d\u8a00<\/p>\n<p>\u597d\u6bd4C++\u4e2d\uff0c\u5b9a\u4e49int\u7c7b\u578b\u9700\u8981\u591a\u5c11\u5b57\u8282\uff0c\u5b9a\u4e49double\u7c7b\u578b\u9700\u8981\u591a\u5c11\u5b57\u8282\u4e00\u6837\uff0cMySQL\u5bf9\u8868\u6bcf\u4e2a\u5217\u4e2d\u7684\u6570\u636e\u4e5f\u4f1a\u5b9e\u884c\u4e25\u683c\u63a7\u5236\uff0c\u8fd9\u662f\u6570\u636e\u9a71\u52a8\u5e94\u7528\u7a0b\u5e8f\u6210\u529f\u7684\u5173\u952e\u3002MySQL\u63d0\u4f9b\u4e86\u4e00\u7ec4\u53ef\u4ee5\u8d4b\u7ed9\u8868\u4e2d\u5404\u4e2a\u5217\u7684\u6570\u636e\u7c7b\u578b\uff0c\u6bcf\u4e2a\u7c7b\u578b\u90fd\u5f3a\u5236\u6570\u636e\u6ee1\u8db3\u4e3a\u8be5\u6570\u636e\u7c7b\u578b\u9884\u5148\u786e\u5b9a\u7684\u4e00\u7ec4\u89c4\u5219\uff0c\u4f8b\u5982\u5927\u5c0f\u3001\u7c7b\u578b\u53ca\u683c\u5f0f\u3002<\/p>\n<p>\u8fd9\u91cc\u5148\u603b\u7ed3\u6570\u636e\u7c7b\u578b\u3002MySQL\u4e2d\u7684\u6570\u636e\u7c7b\u578b\u5927\u7684\u65b9\u9762\u6765\u5206\uff0c\u53ef\u4ee5\u5206\u4e3a\uff1a\u65e5\u671f\u548c\u65f6\u95f4\u3001\u6570\u503c\uff0c\u4ee5\u53ca\u5b57\u7b26\u4e32\u3002\u4e0b\u9762\u5c31\u5206\u5f00\u6765\u8fdb\u884c\u603b\u7ed3\u3002<\/p>\n<p><strong>\u65e5\u671f\u548c\u65f6\u95f4\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<p>MySQL\u6570\u636e\u7c7b\u578b\u542b\u4e49<br \/>\ndate 3\u5b57\u8282\uff0c\u65e5\u671f\uff0c\u683c\u5f0f\uff1a2014-09-18<br \/>\ntime 3\u5b57\u8282\uff0c\u65f6\u95f4\uff0c\u683c\u5f0f\uff1a08:42:30<br \/>\ndatetime 8\u5b57\u8282\uff0c\u65e5\u671f\u65f6\u95f4\uff0c\u683c\u5f0f\uff1a2014-09-18 08:42:30<br \/>\ntimestamp 4\u5b57\u8282\uff0c\u81ea\u52a8\u5b58\u50a8\u8bb0\u5f55\u4fee\u6539\u7684\u65f6\u95f4<br \/>\nyear1\u5b57\u8282\uff0c\u5e74\u4efd<\/p>\n<p><strong>\u6570\u503c\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<p><strong>\u6574\u578b<\/strong><\/p>\n<p>MySQL\u6570\u636e\u7c7b\u578b\u542b\u4e49\uff08\u6709\u7b26\u53f7\uff09<br \/>\ntinyint 1\u5b57\u8282\uff0c\u8303\u56f4\uff08-128~127\uff09<br \/>\nsmallint 2\u5b57\u8282\uff0c\u8303\u56f4\uff08-32768~32767\uff09<br \/>\nmediumint 3\u5b57\u8282\uff0c\u8303\u56f4\uff08-8388608~8388607\uff09<br \/>\nint 4\u5b57\u8282\uff0c\u8303\u56f4\uff08-2147483648~2147483647\uff09<br \/>\nbigint 8\u5b57\u8282\uff0c\u8303\u56f4\uff08+-9.22*10\u768418\u6b21\u65b9\uff09<\/p>\n<p>\u4e0a\u9762\u5b9a\u4e49\u7684\u90fd\u662f\u6709\u7b26\u53f7\u7684\uff0c\u5f53\u7136\u4e86\uff0c\u4e5f\u53ef\u4ee5\u52a0\u4e0aunsigned\u5173\u952e\u5b57\uff0c\u5b9a\u4e49\u6210\u65e0\u7b26\u53f7\u7684\u7c7b\u578b\uff0c\u90a3\u4e48\u5bf9\u5e94\u7684\u53d6\u503c\u8303\u56f4\u5c31\u8981\u7ffb\u7ffb\u4e86\uff0c\u6bd4\u5982\uff1a<\/p>\n<p>tinyint unsigned\u7684\u53d6\u503c\u8303\u56f4\u4e3a0~255\u3002<\/p>\n<p><strong>\u6d6e\u70b9\u578b<\/strong><\/p>\n<p>MySQL\u6570\u636e\u7c7b\u578b\u542b\u4e49<br \/>\nfloat(m, d) 4\u5b57\u8282\uff0c\u5355\u7cbe\u5ea6\u6d6e\u70b9\u578b\uff0cm\u603b\u4e2a\u6570\uff0cd\u5c0f\u6570\u4f4d<br \/>\ndouble(m, d) 8\u5b57\u8282\uff0c\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u578b\uff0cm\u603b\u4e2a\u6570\uff0cd\u5c0f\u6570\u4f4d<br \/>\ndecimal(m, d) decimal\u662f\u5b58\u50a8\u4e3a\u5b57\u7b26\u4e32\u7684\u6d6e\u70b9\u6570<\/p>\n<p>\u6211\u5728MySQL\u4e2d\u5efa\u7acb\u4e86\u4e00\u4e2a\u8868\uff0c\u6709\u4e00\u5217\u4e3afloat(5, 3)\uff1b\u505a\u4e86\u4ee5\u4e0b\u8bd5\u9a8c\uff1a<\/p>\n<p>1.\u63d2\u5165123.45678\uff0c\u6700\u540e\u67e5\u8be2\u5f97\u5230\u7684\u7ed3\u679c\u4e3a99.999\uff1b<br \/>\n2.\u63d2\u5165123.456\uff0c\u6700\u540e\u67e5\u8be2\u7ed3\u679c\u4e3a99.999\uff1b<br \/>\n3.\u63d2\u516512.34567\uff0c\u6700\u540e\u67e5\u8be2\u7ed3\u679c\u4e3a12.346\uff1b<\/p>\n<p>\u6240\u4ee5\uff0c\u5728\u4f7f\u7528\u6d6e\u70b9\u578b\u7684\u65f6\u5019\uff0c\u8fd8\u662f\u8981\u6ce8\u610f\u9677\u9631\u7684\uff0c\u8981\u4ee5\u63d2\u5165\u6570\u636e\u5e93\u4e2d\u7684\u5b9e\u9645\u7ed3\u679c\u4e3a\u51c6\u3002<\/p>\n<p><strong>\u5b57\u7b26\u4e32\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<p>MySQL\u6570\u636e\u7c7b\u578b\u542b\u4e49<br \/>\nchar(n)\u56fa\u5b9a\u957f\u5ea6\uff0c\u6700\u591a255\u4e2a\u5b57\u7b26<br \/>\nvarchar(n)\u53ef\u53d8\u957f\u5ea6\uff0c\u6700\u591a65535\u4e2a\u5b57\u7b26<br \/>\ntinytext\u53ef\u53d8\u957f\u5ea6\uff0c\u6700\u591a255\u4e2a\u5b57\u7b26<br \/>\ntext\u53ef\u53d8\u957f\u5ea6\uff0c\u6700\u591a65535\u4e2a\u5b57\u7b26<br \/>\nmediumtext\u53ef\u53d8\u957f\u5ea6\uff0c\u6700\u591a2\u768424\u6b21\u65b9-1\u4e2a\u5b57\u7b26<br \/>\nlongtext\u53ef\u53d8\u957f\u5ea6\uff0c\u6700\u591a2\u768432\u6b21\u65b9-1\u4e2a\u5b57\u7b26<\/p>\n<p>1.char\uff08n\uff09\u548cvarchar\uff08n\uff09\u4e2d\u62ec\u53f7\u4e2dn\u4ee3\u8868\u5b57\u7b26\u7684\u4e2a\u6570\uff0c\u5e76\u4e0d\u4ee3\u8868\u5b57\u8282\u4e2a\u6570\uff0c\u6240\u4ee5\u5f53\u4f7f\u7528\u4e86\u4e2d\u6587\u7684\u65f6\u5019(UTF8)\u610f\u5473\u7740\u53ef\u4ee5\u63d2\u5165m\u4e2a\u4e2d\u6587\uff0c\u4f46\u662f\u5b9e\u9645\u4f1a\u5360\u7528m*3\u4e2a\u5b57\u8282\u3002<br \/>\n2.\u540c\u65f6char\u548cvarchar\u6700\u5927\u7684\u533a\u522b\u5c31\u5728\u4e8echar\u4e0d\u7ba1\u5b9e\u9645value\u90fd\u4f1a\u5360\u7528n\u4e2a\u5b57\u7b26\u7684\u7a7a\u95f4\uff0c\u800cvarchar\u53ea\u4f1a\u5360\u7528\u5b9e\u9645\u5b57\u7b26\u5e94\u8be5\u5360\u7528\u7684\u7a7a\u95f4+1\uff0c\u5e76\u4e14\u5b9e\u9645\u7a7a\u95f4+1&lt;=n\u3002<br \/>\n3.\u8d85\u8fc7char\u548cvarchar\u7684n\u8bbe\u7f6e\u540e\uff0c\u5b57\u7b26\u4e32\u4f1a\u88ab\u622a\u65ad\u3002<br \/>\n4.char\u7684\u4e0a\u9650\u4e3a255\u5b57\u8282\uff0cvarchar\u7684\u4e0a\u965065535\u5b57\u8282\uff0ctext\u7684\u4e0a\u9650\u4e3a65535\u3002<br \/>\n5.char\u5728\u5b58\u50a8\u7684\u65f6\u5019\u4f1a\u622a\u65ad\u5c3e\u90e8\u7684\u7a7a\u683c\uff0cvarchar\u548ctext\u4e0d\u4f1a\u3002<br \/>\n6.varchar\u4f1a\u4f7f\u75281-3\u4e2a\u5b57\u8282\u6765\u5b58\u50a8\u957f\u5ea6\uff0ctext\u4e0d\u4f1a\u3002<\/p>\n<p><strong>\u5176\u5b83\u7c7b\u578b<\/strong><\/p>\n<p>1.enum(\u201cmember1\u2033, \u201cmember2\u2033, \u2026 \u201cmember65535\u2033)<br \/>\nenum\u6570\u636e\u7c7b\u578b\u5c31\u662f\u5b9a\u4e49\u4e86\u4e00\u79cd\u679a\u4e3e\uff0c\u6700\u591a\u5305\u542b65535\u4e2a\u4e0d\u540c\u7684\u6210\u5458\u3002\u5f53\u5b9a\u4e49\u4e86\u4e00\u4e2aenum\u7684\u5217\u65f6\uff0c\u8be5\u5217\u7684\u503c\u9650\u5236\u4e3a\u5217\u5b9a\u4e49\u4e2d\u58f0\u660e\u7684\u503c\u3002\u5982\u679c\u5217\u58f0\u660e\u5305\u542bNULL\u5c5e\u6027\uff0c\u5219NULL\u5c06\u88ab\u8ba4\u4e3a\u662f\u4e00\u4e2a\u6709\u6548\u503c\uff0c\u5e76\u4e14\u662f\u9ed8\u8ba4\u503c\u3002\u5982\u679c\u58f0\u660e\u4e86NOT NULL\uff0c\u5219\u5217\u8868\u7684\u7b2c\u4e00\u4e2a\u6210\u5458\u662f\u9ed8\u8ba4\u503c\u3002<\/p>\n<p>2.set(\u201cmember\u201d, \u201cmember2\u2033, \u2026 \u201cmember64\u2033)<br \/>\nset\u6570\u636e\u7c7b\u578b\u4e3a\u6307\u5b9a\u4e00\u7ec4\u9884\u5b9a\u4e49\u503c\u4e2d\u7684\u96f6\u4e2a\u6216\u591a\u4e2a\u503c\u63d0\u4f9b\u4e86\u4e00\u79cd\u65b9\u6cd5\uff0c\u8fd9\u7ec4\u503c\u6700\u591a\u5305\u62ec64\u4e2a\u6210\u5458\u3002\u503c\u7684\u9009\u62e9\u9650\u5236\u4e3a\u5217\u5b9a\u4e49\u4e2d\u58f0\u660e\u7684\u503c\u3002<\/p>\n<p><strong>\u6570\u636e\u7c7b\u578b\u5c5e\u6027<\/strong><\/p>\n<p>\u4e0a\u9762\u5927\u6982\u603b\u7ed3\u4e86MySQL\u4e2d\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5f53\u7136\u4e86\uff0c\u4e0a\u9762\u7684\u603b\u7ed3\u80af\u5b9a\u662f\u4e0d\u5168\u9762\u7684\uff0c\u5982\u679c\u8981\u975e\u5e38\u5168\u9762\u7684\u603b\u7ed3\u8fd9\u4e9b\u5185\u5bb9\uff0c\u597d\u51e0\u7bc7\u6587\u7ae0\u90fd\u4e0d\u591f\u7684\u3002\u4e0b\u9762\u5c31\u518d\u6765\u603b\u7ed3\u4e00\u4e9b\u5e38\u7528\u7684\u5c5e\u6027\u3002<\/p>\n<p><strong>1.auto_increment<\/strong><\/p>\n<p>auto_increment\u80fd\u4e3a\u65b0\u63d2\u5165\u7684\u884c\u8d4b\u4e00\u4e2a\u552f\u4e00\u7684\u6574\u6570\u6807\u8bc6\u7b26\u3002\u4e3a\u5217\u8d4b\u6b64\u5c5e\u6027\u5c06\u4e3a\u6bcf\u4e2a\u65b0\u63d2\u5165\u7684\u884c\u8d4b\u503c\u4e3a\u4e0a\u4e00\u6b21\u63d2\u5165\u7684ID+1\u3002<\/p>\n<p>MySQL\u8981\u6c42\u5c06auto_increment\u5c5e\u6027\u7528\u4e8e\u4f5c\u4e3a\u4e3b\u952e\u7684\u5217\u3002\u6b64\u5916\uff0c\u6bcf\u4e2a\u8868\u53ea\u5141\u8bb8\u6709\u4e00\u4e2aauto_increment\u5217\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"prettyprint prettyprinted\"><span class=\"pln\">id smallint <\/span><span class=\"kwd\">not<\/span> <span class=\"kwd\">null<\/span><span class=\"pln\"> auto_increment primary key<\/span><\/pre>\n<p><strong>2.binary<\/strong><\/p>\n<p>binary\u5c5e\u6027\u53ea\u7528\u4e8echar\u548cvarchar\u503c\u3002\u5f53\u4e3a\u5217\u6307\u5b9a\u4e86\u8be5\u5c5e\u6027\u65f6\uff0c\u5c06\u4ee5\u533a\u5206\u5927\u5c0f\u5199\u7684\u65b9\u5f0f\u6392\u5e8f\u3002\u4e0e\u4e4b\u76f8\u53cd\uff0c\u5ffd\u7565binary\u5c5e\u6027\u65f6\uff0c\u5c06\u4f7f\u7528\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u7684\u65b9\u5f0f\u6392\u5e8f\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"prettyprint prettyprinted\"><span class=\"pln\">hostname <\/span><span class=\"kwd\">char<\/span><span class=\"pun\">(<\/span><span class=\"lit\">25<\/span><span class=\"pun\">)<\/span><span class=\"pln\"> binary <\/span><span class=\"kwd\">not<\/span> <span class=\"kwd\">null<\/span><\/pre>\n<p><strong>3.default<\/strong><\/p>\n<p>default\u5c5e\u6027\u786e\u4fdd\u5728\u6ca1\u6709\u4efb\u4f55\u503c\u53ef\u7528\u7684\u60c5\u51b5\u4e0b\uff0c\u8d4b\u4e88\u67d0\u4e2a\u5e38\u91cf\u503c\uff0c\u8fd9\u4e2a\u503c\u5fc5\u987b\u662f\u5e38\u91cf\uff0c\u56e0\u4e3aMySQL\u4e0d\u5141\u8bb8\u63d2\u5165\u51fd\u6570\u6216\u8868\u8fbe\u5f0f\u503c\u3002\u6b64\u5916\uff0c\u6b64\u5c5e\u6027\u65e0\u6cd5\u7528\u4e8eBLOB\u6216TEXT\u5217\u3002\u5982\u679c\u5df2\u7ecf\u4e3a\u6b64\u5217\u6307\u5b9a\u4e86NULL\u5c5e\u6027\uff0c\u6ca1\u6709\u6307\u5b9a\u9ed8\u8ba4\u503c\u65f6\u9ed8\u8ba4\u503c\u5c06\u4e3aNULL\uff0c\u5426\u5219\u9ed8\u8ba4\u503c\u5c06\u4f9d\u8d56\u4e8e\u5b57\u6bb5\u7684\u6570\u636e\u7c7b\u578b\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"prettyprint prettyprinted\"><span class=\"pln\">subscribed <\/span><span class=\"kwd\">enum<\/span><span class=\"pun\">(<\/span><span class=\"str\">'0'<\/span><span class=\"pun\">,<\/span> <span class=\"str\">'1'<\/span><span class=\"pun\">)<\/span> <span class=\"kwd\">not<\/span> <span class=\"kwd\">null<\/span> <span class=\"kwd\">default<\/span> <span class=\"str\">'0'<\/span><\/pre>\n<p><strong>4.index<\/strong><\/p>\n<p>\u5982\u679c\u6240\u6709\u5176\u4ed6\u56e0\u7d20\u90fd\u76f8\u540c\uff0c\u8981\u52a0\u901f\u6570\u636e\u5e93\u67e5\u8be2\uff0c\u4f7f\u7528\u7d22\u5f15\u901a\u5e38\u662f\u6700\u91cd\u8981\u7684\u4e00\u4e2a\u6b65\u9aa4\u3002\u7d22\u5f15\u4e00\u4e2a\u5217\u4f1a\u4e3a\u8be5\u5217\u521b\u5efa\u4e00\u4e2a\u6709\u5e8f\u7684\u952e\u6570\u7ec4\uff0c\u6bcf\u4e2a\u952e\u6307\u5411\u5176\u76f8\u5e94\u7684\u8868\u884c\u3002\u4ee5\u540e\u9488\u5bf9\u8f93\u5165\u6761\u4ef6\u53ef\u4ee5\u641c\u7d22\u8fd9\u4e2a\u6709\u5e8f\u7684\u952e\u6570\u7ec4\uff0c\u4e0e\u641c\u7d22\u6574\u4e2a\u672a\u7d22\u5f15\u7684\u8868\u76f8\u6bd4\uff0c\u8fd9\u5c06\u5728\u6027\u80fd\u65b9\u9762\u5f97\u5230\u6781\u5927\u7684\u63d0\u5347\u3002<\/p>\n<pre class=\"prettyprint prettyprinted\"><span class=\"pln\">create table employees\r\n<\/span><span class=\"pun\">(<\/span><span class=\"pln\">\r\nid varchar<\/span><span class=\"pun\">(<\/span><span class=\"lit\">9<\/span><span class=\"pun\">)<\/span> <span class=\"kwd\">not<\/span> <span class=\"kwd\">null<\/span><span class=\"pun\">,<\/span><span class=\"pln\">\r\nfirstname varchar<\/span><span class=\"pun\">(<\/span><span class=\"lit\">15<\/span><span class=\"pun\">)<\/span> <span class=\"kwd\">not<\/span> <span class=\"kwd\">null<\/span><span class=\"pun\">,<\/span><span class=\"pln\">\r\nlastname varchar<\/span><span class=\"pun\">(<\/span><span class=\"lit\">25<\/span><span class=\"pun\">)<\/span> <span class=\"kwd\">not<\/span> <span class=\"kwd\">null<\/span><span class=\"pun\">,<\/span><span class=\"pln\">\r\nemail varchar<\/span><span class=\"pun\">(<\/span><span class=\"lit\">45<\/span><span class=\"pun\">)<\/span> <span class=\"kwd\">not<\/span> <span class=\"kwd\">null<\/span><span class=\"pun\">,<\/span><span class=\"pln\">\r\nphone varchar<\/span><span class=\"pun\">(<\/span><span class=\"lit\">10<\/span><span class=\"pun\">)<\/span> <span class=\"kwd\">not<\/span> <span class=\"kwd\">null<\/span><span class=\"pun\">,<\/span><span class=\"pln\">\r\nindex lastname<\/span><span class=\"pun\">(<\/span><span class=\"pln\">lastname<\/span><span class=\"pun\">),<\/span><span class=\"pln\">\r\nprimary key<\/span><span class=\"pun\">(<\/span><span class=\"pln\">id<\/span><span class=\"pun\">)<\/span>\r\n<span class=\"pun\">);<\/span><\/pre>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u5229\u7528MySQL\u7684create index\u547d\u4ee4\u5728\u521b\u5efa\u8868\u4e4b\u540e\u589e\u52a0\u7d22\u5f15\uff1a<\/p>\n<pre class=\"prettyprint prettyprinted\"><span class=\"pln\">create index lastname on employees <\/span><span class=\"pun\">(<\/span><span class=\"pln\">lastname<\/span><span class=\"pun\">(<\/span><span class=\"lit\">7<\/span><span class=\"pun\">));<\/span><\/pre>\n<p>\u8fd9\u4e00\u6b21\u53ea\u7d22\u5f15\u4e86\u540d\u5b57\u7684\u524d7\u4e2a\u5b57\u7b26\uff0c\u56e0\u4e3a\u53ef\u80fd\u4e0d\u9700\u8981\u5176\u5b83\u5b57\u6bcd\u6765\u533a\u5206\u4e0d\u540c\u7684\u540d\u5b57\u3002\u56e0\u4e3a\u4f7f\u7528\u8f83\u5c0f\u7684\u7d22\u5f15\u65f6\u6027\u80fd\u66f4\u597d\uff0c\u6240\u4ee5\u5e94\u5f53\u5728\u5b9e\u8df5\u4e2d\u5c3d\u91cf\u4f7f\u7528\u5c0f\u7684\u7d22\u5f15\u3002<\/p>\n<p><strong>5.not null<\/strong><\/p>\n<p>\u5982\u679c\u5c06\u4e00\u4e2a\u5217\u5b9a\u4e49\u4e3anot null\uff0c\u5c06\u4e0d\u5141\u8bb8\u5411\u8be5\u5217\u63d2\u5165null\u503c\u3002\u5efa\u8bae\u5728\u91cd\u8981\u60c5\u51b5\u4e0b\u59cb\u7ec8\u4f7f\u7528not null\u5c5e\u6027\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u57fa\u672c\u9a8c\u8bc1\uff0c\u786e\u4fdd\u5df2\u7ecf\u5411\u67e5\u8be2\u4f20\u9012\u4e86\u6240\u6709\u5fc5\u8981\u7684\u503c\u3002<\/p>\n<p><strong>6.null<\/strong><\/p>\n<p>\u4e3a\u5217\u6307\u5b9anull\u5c5e\u6027\u65f6\uff0c\u8be5\u5217\u53ef\u4ee5\u4fdd\u6301\u4e3a\u7a7a\uff0c\u800c\u4e0d\u8bba\u884c\u4e2d\u5176\u5b83\u5217\u662f\u5426\u5df2\u7ecf\u88ab\u586b\u5145\u3002\u8bb0\u4f4f\uff0cnull\u7cbe\u786e\u7684\u8bf4\u6cd5\u662f\u201c\u65e0\u201d\uff0c\u800c\u4e0d\u662f\u7a7a\u5b57\u7b26\u4e32\u62160\u3002<\/p>\n<p><strong>7.primary key<\/strong><\/p>\n<p>primary key\u5c5e\u6027\u7528\u4e8e\u786e\u4fdd\u6307\u5b9a\u884c\u7684\u552f\u4e00\u6027\u3002\u6307\u5b9a\u4e3a\u4e3b\u952e\u7684\u5217\u4e2d\uff0c\u503c\u4e0d\u80fd\u91cd\u590d\uff0c\u4e5f\u4e0d\u80fd\u4e3a\u7a7a\u3002\u4e3a\u6307\u5b9a\u4e3a\u4e3b\u952e\u7684\u5217\u8d4b\u4e88auto_increment\u5c5e\u6027\u662f\u5f88\u5e38\u89c1\u7684\uff0c\u56e0\u4e3a\u6b64\u5217\u4e0d\u5fc5\u4e0e\u884c\u6570\u636e\u6709\u4efb\u4f55\u5173\u7cfb\uff0c\u800c\u53ea\u662f\u4f5c\u4e3a\u4e00\u4e2a\u552f\u4e00\u6807\u8bc6\u7b26\u3002\u4e3b\u952e\u53c8\u5206\u4e3a\u4ee5\u4e0b\u4e24\u79cd\uff1a<\/p>\n<p>(1)\u5355\u5b57\u6bb5\u4e3b\u952e<\/p>\n<p>\u5982\u679c\u8f93\u5165\u5230\u6570\u636e\u5e93\u4e2d\u7684\u6bcf\u884c\u90fd\u5df2\u7ecf\u6709\u4e0d\u53ef\u4fee\u6539\u7684\u552f\u4e00\u6807\u8bc6\u7b26\uff0c\u4e00\u822c\u4f1a\u4f7f\u7528\u5355\u5b57\u6bb5\u4e3b\u952e\u3002\u6ce8\u610f\uff0c\u6b64\u4e3b\u952e\u4e00\u65e6\u8bbe\u7f6e\u5c31\u4e0d\u80fd\u518d\u4fee\u6539\u3002<\/p>\n<p>(2)\u591a\u5b57\u6bb5\u4e3b\u952e<\/p>\n<p>\u5982\u679c\u8bb0\u5f55\u4e2d\u4efb\u4f55\u4e00\u4e2a\u5b57\u6bb5\u90fd\u4e0d\u53ef\u80fd\u4fdd\u8bc1\u552f\u4e00\u6027\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u591a\u5b57\u6bb5\u4e3b\u952e\u3002\u8fd9\u65f6\uff0c\u591a\u4e2a\u5b57\u6bb5\u8054\u5408\u8d77\u6765\u786e\u4fdd\u552f\u4e00\u6027\u3002\u5982\u679c\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\uff0c\u6307\u5b9a\u4e00\u4e2aauto_increment\u6574\u6570\u4f5c\u4e3a\u4e3b\u952e\u662f\u66f4\u597d\u7684\u529e\u6cd5\u3002<\/p>\n<p><strong>8.unique<\/strong><\/p>\n<p>\u88ab\u8d4b\u4e88unique\u5c5e\u6027\u7684\u5217\u5c06\u786e\u4fdd\u6240\u6709\u503c\u90fd\u6709\u4e0d\u540c\u7684\u503c\uff0c\u53ea\u662fnull\u503c\u53ef\u4ee5\u91cd\u590d\u3002\u4e00\u822c\u4f1a\u6307\u5b9a\u4e00\u4e2a\u5217\u4e3aunique\uff0c\u4ee5\u786e\u4fdd\u8be5\u5217\u7684\u6240\u6709\u503c\u90fd\u4e0d\u540c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"prettyprint prettyprinted\"><span class=\"pln\">email varchar<\/span><span class=\"pun\">(<\/span><span class=\"lit\">45<\/span><span class=\"pun\">)<\/span><span class=\"pln\"> unique<\/span><\/pre>\n<p><strong>9.zerofill<\/strong><\/p>\n<p>zerofill\u5c5e\u6027\u53ef\u7528\u4e8e\u4efb\u4f55\u6570\u503c\u7c7b\u578b\uff0c\u75280\u586b\u5145\u6240\u6709\u5269\u4f59\u5b57\u6bb5\u7a7a\u95f4\u3002\u4f8b\u5982\uff0c\u65e0\u7b26\u53f7int\u7684\u9ed8\u8ba4\u5bbd\u5ea6\u662f10\uff1b\u56e0\u6b64\uff0c\u5f53\u201c\u96f6\u586b\u5145\u201d\u7684int\u503c\u4e3a4\u65f6\uff0c\u5c06\u8868\u793a\u5b83\u4e3a0000000004\u3002\u4f8b\u5982\uff1a<\/p>\n<pre class=\"prettyprint prettyprinted\"><span class=\"pln\">orderid <\/span><span class=\"kwd\">int<\/span> <span class=\"kwd\">unsigned<\/span><span class=\"pln\"> zerofill <\/span><span class=\"kwd\">not<\/span> <span class=\"kwd\">null<\/span><\/pre>\n<p>\u603b\u7ed3\u5b8c\u6bd5\uff01\uff01\uff01<\/p>\n<p>\u53c2\u8003\uff1ajb51.net\/article\/55853.htm<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u597d\u6bd4C++\u4e2d\uff0c\u5b9a\u4e49int\u7c7b\u578b\u9700\u8981\u591a\u5c11\u5b57\u8282\uff0c\u5b9a\u4e49double\u7c7b\u578b\u9700\u8981\u591a\u5c11\u5b57\u8282&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/freesilo.com\/?p=354\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-354","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/354","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=354"}],"version-history":[{"count":1,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/354\/revisions"}],"predecessor-version":[{"id":355,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/354\/revisions\/355"}],"wp:attachment":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}