{"id":139688,"date":"2024-10-31T19:50:31","date_gmt":"2024-10-31T11:50:31","guid":{"rendered":"https:\/\/server.hk\/cnblog\/139688\/"},"modified":"2024-10-31T19:50:31","modified_gmt":"2024-10-31T11:50:31","slug":"sql-server%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e6%96%87%e6%9c%ac%e5%92%8c%e5%9c%96%e5%bd%a2%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/139688\/","title":{"rendered":"SQL Server\u6578\u64da\u985e\u578b\u6587\u672c\u548c\u5716\u5f62\u6578\u64da\u985e\u578b"},"content":{"rendered":"<h1 id=\"sql-server%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e6%96%87%e6%9c%ac%e5%92%8c%e5%9c%96%e5%bd%a2%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-MxUmkeWMEz\">SQL Server\u6578\u64da\u985e\u578b\u6587\u672c\u548c\u5716\u5f62\u6578\u64da\u985e\u578b<\/h1>\n<p>\u5728SQL Server\u4e2d\uff0c\u6578\u64da\u985e\u578b\u7684\u9078\u64c7\u5c0d\u65bc\u6578\u64da\u7684\u5b58\u5132\u548c\u8655\u7406\u81f3\u95dc\u91cd\u8981\u3002\u672c\u6587\u5c07\u91cd\u9ede\u4ecb\u7d39SQL Server\u4e2d\u7684\u6587\u672c\u6578\u64da\u985e\u578b\u548c\u5716\u5f62\u6578\u64da\u985e\u578b\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3\u9019\u4e9b\u6578\u64da\u985e\u578b\u7684\u7279\u6027\u53ca\u5176\u4f7f\u7528\u5834\u666f\u3002<\/p>\n<h2 id=\"%e6%96%87%e6%9c%ac%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-MxUmkeWMEz\">\u6587\u672c\u6578\u64da\u985e\u578b<\/h2>\n<p>\u6587\u672c\u6578\u64da\u985e\u578b\u4e3b\u8981\u7528\u65bc\u5b58\u5132\u5b57\u7b26\u6578\u64da\u3002SQL Server\u63d0\u4f9b\u4e86\u5e7e\u7a2e\u4e0d\u540c\u7684\u6587\u672c\u6578\u64da\u985e\u578b\uff0c\u4e3b\u8981\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>CHAR(n)<\/strong>: \u56fa\u5b9a\u9577\u5ea6\u7684\u5b57\u7b26\u6578\u64da\u985e\u578b\uff0c\u6700\u591a\u53ef\u5b58\u51328000\u500b\u5b57\u7b26\u3002\u7576\u5b58\u5132\u7684\u5b57\u7b26\u5c11\u65bcn\u6642\uff0c\u6703\u7528\u7a7a\u683c\u586b\u5145\u3002<\/li>\n<li><strong>VARCHAR(n)<\/strong>: \u53ef\u8b8a\u9577\u5ea6\u7684\u5b57\u7b26\u6578\u64da\u985e\u578b\uff0c\u6700\u591a\u53ef\u5b58\u51328000\u500b\u5b57\u7b26\u3002\u9019\u7a2e\u6578\u64da\u985e\u578b\u6839\u64da\u5be6\u969b\u5b58\u5132\u7684\u5b57\u7b26\u6578\u91cf\u4f86\u4f54\u7528\u7a7a\u9593\u3002<\/li>\n<li><strong>NCHAR(n)<\/strong>: \u56fa\u5b9a\u9577\u5ea6\u7684Unicode\u5b57\u7b26\u6578\u64da\u985e\u578b\uff0c\u6700\u591a\u53ef\u5b58\u51324000\u500b\u5b57\u7b26\u3002\u9069\u5408\u5b58\u5132\u591a\u8a9e\u8a00\u5b57\u7b26\u3002<\/li>\n<li><strong>NVARCHAR(n)<\/strong>: \u53ef\u8b8a\u9577\u5ea6\u7684Unicode\u5b57\u7b26\u6578\u64da\u985e\u578b\uff0c\u6700\u591a\u53ef\u5b58\u51324000\u500b\u5b57\u7b26\u3002\u8207VARCHAR\u985e\u4f3c\uff0c\u4f46\u652f\u6301Unicode\u5b57\u7b26\u3002<\/li>\n<li><strong>TEXT<\/strong>: \u7528\u65bc\u5b58\u5132\u5927\u91cf\u6587\u672c\u6578\u64da\uff0c\u6700\u591a\u53ef\u5b58\u51322^31-1\u500b\u5b57\u7b26\u3002\u6b64\u6578\u64da\u985e\u578b\u5728SQL Server 2016\u53ca\u4ee5\u5f8c\u7248\u672c\u4e2d\u5df2\u88abVARCHAR(MAX)\u53d6\u4ee3\u3002<\/li>\n<li><strong>NTEXT<\/strong>: \u7528\u65bc\u5b58\u5132\u5927\u91cfUnicode\u6587\u672c\u6578\u64da\uff0c\u6700\u591a\u53ef\u5b58\u51322^30-1\u500b\u5b57\u7b26\u3002\u6b64\u6578\u64da\u985e\u578b\u5728SQL Server 2016\u53ca\u4ee5\u5f8c\u7248\u672c\u4e2d\u5df2\u88abNVARCHAR(MAX)\u53d6\u4ee3\u3002<\/li>\n<\/ul>\n<h3 id=\"%e6%96%87%e6%9c%ac%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e7%9a%84%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b-MxUmkeWMEz\">\u6587\u672c\u6578\u64da\u985e\u578b\u7684\u4f7f\u7528\u793a\u4f8b<\/h3>\n<pre><code>CREATE TABLE ExampleText (\n    ID INT PRIMARY KEY,\n    Name VARCHAR(100),\n    Description TEXT\n);\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b\u540d\u70baExampleText\u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u500bVARCHAR\u985e\u578b\u7684Name\u6b04\u4f4d\u548c\u4e00\u500bTEXT\u985e\u578b\u7684Description\u6b04\u4f4d\u3002\u9019\u6a23\u7684\u8a2d\u8a08\u4f7f\u5f97\u6211\u5011\u53ef\u4ee5\u9748\u6d3b\u5730\u5b58\u5132\u4e0d\u540c\u9577\u5ea6\u7684\u6587\u672c\u6578\u64da\u3002<\/p>\n<h2 id=\"%e5%9c%96%e5%bd%a2%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-MxUmkeWMEz\">\u5716\u5f62\u6578\u64da\u985e\u578b<\/h2>\n<p>\u5716\u5f62\u6578\u64da\u985e\u578b\u4e3b\u8981\u7528\u65bc\u5b58\u5132\u4e8c\u9032\u5236\u6578\u64da\uff0c\u5982\u5716\u50cf\u3001\u97f3\u983b\u548c\u8996\u983b\u7b49\u3002SQL Server\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u5e7e\u7a2e\u5716\u5f62\u6578\u64da\u985e\u578b\uff1a<\/p>\n<ul>\n<li><strong>BINARY(n)<\/strong>: \u56fa\u5b9a\u9577\u5ea6\u7684\u4e8c\u9032\u5236\u6578\u64da\u985e\u578b\uff0c\u6700\u591a\u53ef\u5b58\u51328000\u500b\u5b57\u7bc0\u3002<\/li>\n<li><strong>VARBINARY(n)<\/strong>: \u53ef\u8b8a\u9577\u5ea6\u7684\u4e8c\u9032\u5236\u6578\u64da\u985e\u578b\uff0c\u6700\u591a\u53ef\u5b58\u51328000\u500b\u5b57\u7bc0\u3002<\/li>\n<li><strong>IMAGE<\/strong>: \u7528\u65bc\u5b58\u5132\u5927\u91cf\u4e8c\u9032\u5236\u6578\u64da\uff0c\u6700\u591a\u53ef\u5b58\u51322^31-1\u500b\u5b57\u7bc0\u3002\u6b64\u6578\u64da\u985e\u578b\u5728SQL Server 2016\u53ca\u4ee5\u5f8c\u7248\u672c\u4e2d\u5df2\u88abVARBINARY(MAX)\u53d6\u4ee3\u3002<\/li>\n<\/ul>\n<h3 id=\"%e5%9c%96%e5%bd%a2%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e7%9a%84%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b-MxUmkeWMEz\">\u5716\u5f62\u6578\u64da\u985e\u578b\u7684\u4f7f\u7528\u793a\u4f8b<\/h3>\n<pre><code>CREATE TABLE ExampleImage (\n    ID INT PRIMARY KEY,\n    ImageData VARBINARY(MAX)\n);\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b\u540d\u70baExampleImage\u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u500bVARBINARY(MAX)\u985e\u578b\u7684ImageData\u6b04\u4f4d\uff0c\u7528\u65bc\u5b58\u5132\u4efb\u610f\u5927\u5c0f\u7684\u4e8c\u9032\u5236\u6578\u64da\uff0c\u5982\u5716\u50cf\u6587\u4ef6\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-MxUmkeWMEz\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u9078\u64c7SQL Server\u7684\u6578\u64da\u985e\u578b\u6642\uff0c\u4e86\u89e3\u6587\u672c\u548c\u5716\u5f62\u6578\u64da\u985e\u578b\u7684\u7279\u6027\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u6839\u64da\u5be6\u969b\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u985e\u578b\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u6548\u7387\u3002\u5c0d\u65bc\u9700\u8981\u9748\u6d3b\u5b58\u5132\u6587\u672c\u6216\u4e8c\u9032\u5236\u6578\u64da\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u985e\u578b\u5c07\u6709\u52a9\u65bc\u66f4\u597d\u5730\u7ba1\u7406\u548c\u8655\u7406\u6578\u64da\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u7528\u6236\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f\u6578\u64da\u5eab\u7ba1\u7406\u9084\u662f\u61c9\u7528\u90e8\u7f72\uff0c\u6211\u5011\u7684\u670d\u52d9\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3SQL Server\u4e2d\u7684\u6587\u672c\u548c\u5716\u5f62\u6578\u64da\u985e\u578b\uff0c\u63a2\u7d22\u5176\u7279\u6027\u3001\u7528\u9014\u53ca\u6700\u4f73\u5be6\u8e10\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u6548\u7387\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-139688","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/139688","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=139688"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/139688\/revisions"}],"predecessor-version":[{"id":139689,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/139688\/revisions\/139689"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=139688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=139688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=139688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}