{"id":141329,"date":"2024-10-31T21:38:26","date_gmt":"2024-10-31T13:38:26","guid":{"rendered":"https:\/\/server.hk\/cnblog\/141329\/"},"modified":"2024-10-31T21:38:27","modified_gmt":"2024-10-31T13:38:27","slug":"sql-server-%e4%b8%ad%e7%9a%84%e4%bd%8d%e9%81%8b%e7%ae%97%ef%bc%9a%e8%a7%a3%e9%8e%96%e4%bf%a1%e6%81%af%e9%9a%b1%e8%97%8f%e4%b9%8b%e8%ac%8e%ef%bc%88sqlserver-%e4%bd%8d%e9%81%8b%e7%ae%97%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/141329\/","title":{"rendered":"SQL Server \u4e2d\u7684\u4f4d\u904b\u7b97\uff1a\u89e3\u9396\u4fe1\u606f\u96b1\u85cf\u4e4b\u8b0e\uff08sqlserver \u4f4d\u904b\u7b97\uff09"},"content":{"rendered":"<h1 id=\"sql-server-%e4%b8%ad%e7%9a%84%e4%bd%8d%e9%81%8b%e7%ae%97%ef%bc%9a%e8%a7%a3%e9%8e%96%e4%bf%a1%e6%81%af%e9%9a%b1%e8%97%8f%e4%b9%8b%e8%ac%8e-IwyXdCEmDn\">SQL Server \u4e2d\u7684\u4f4d\u904b\u7b97\uff1a\u89e3\u9396\u4fe1\u606f\u96b1\u85cf\u4e4b\u8b0e<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0cSQL Server \u662f\u4e00\u500b\u5ee3\u6cdb\u4f7f\u7528\u7684\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u3002\u5b83\u4e0d\u50c5\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u6578\u64da\u5b58\u5132\u548c\u6aa2\u7d22\u529f\u80fd\uff0c\u9084\u652f\u6301\u591a\u7a2e\u6578\u64da\u64cd\u4f5c\uff0c\u5305\u62ec\u4f4d\u904b\u7b97\u3002\u4f4d\u904b\u7b97\u662f\u4e00\u7a2e\u5728\u4e8c\u9032\u5236\u6578\u64da\u4e0a\u9032\u884c\u64cd\u4f5c\u7684\u6280\u8853\uff0c\u80fd\u5920\u6709\u6548\u5730\u8655\u7406\u548c\u5b58\u5132\u4fe1\u606f\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e SQL Server \u4e2d\u7684\u4f4d\u904b\u7b97\uff0c\u4e26\u63d0\u4f9b\u5be6\u969b\u7684\u61c9\u7528\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e4%bd%8d%e9%81%8b%e7%ae%97%ef%bc%9f-IwyXdCEmDn\">\u4ec0\u9ebc\u662f\u4f4d\u904b\u7b97\uff1f<\/h2>\n<p>\u4f4d\u904b\u7b97\u662f\u5c0d\u4e8c\u9032\u5236\u6578\u5b57\u7684\u64cd\u4f5c\uff0c\u9019\u4e9b\u64cd\u4f5c\u5305\u62ec\u8207\uff08AND\uff09\u3001\u6216\uff08OR\uff09\u3001\u975e\uff08NOT\uff09\u3001\u7570\u6216\uff08XOR\uff09\u7b49\u3002\u9019\u4e9b\u904b\u7b97\u7b26\u53ef\u4ee5\u76f4\u63a5\u4f5c\u7528\u65bc\u6574\u6578\u985e\u578b\u7684\u6578\u64da\uff0c\u4e26\u4e14\u5728 SQL Server \u4e2d\uff0c\u4f4d\u904b\u7b97\u901a\u5e38\u7528\u65bc\u8655\u7406\u6a19\u8a8c\u4f4d\uff08flags\uff09\u6216\u72c0\u614b\u78bc\uff08status codes\uff09\u3002<\/p>\n<h2 id=\"sql-server-%e4%b8%ad%e7%9a%84%e4%bd%8d%e9%81%8b%e7%ae%97%e7%ac%a6-IwyXdCEmDn\">SQL Server \u4e2d\u7684\u4f4d\u904b\u7b97\u7b26<\/h2>\n<p>\u5728 SQL Server \u4e2d\uff0c\u4e3b\u8981\u7684\u4f4d\u904b\u7b97\u7b26\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>&amp;<\/code>\uff1a\u4f4d\u8207\u904b\u7b97\u7b26<\/li>\n<li><code>|<\/code>\uff1a\u4f4d\u6216\u904b\u7b97\u7b26<\/li>\n<li><code>^<\/code>\uff1a\u4f4d\u7570\u6216\u904b\u7b97\u7b26<\/li>\n<li><code>~<\/code>\uff1a\u4f4d\u975e\u904b\u7b97\u7b26<\/li>\n<\/ul>\n<h3 id=\"%e4%bd%8d%e8%88%87%e9%81%8b%e7%ae%97%e7%ac%a6%ef%bc%88and%ef%bc%89-IwyXdCEmDn\">\u4f4d\u8207\u904b\u7b97\u7b26\uff08AND\uff09<\/h3>\n<p>\u4f4d\u8207\u904b\u7b97\u7b26\u7528\u65bc\u6aa2\u67e5\u5169\u500b\u6578\u5b57\u7684\u76f8\u540c\u4f4d\u662f\u5426\u90fd\u70ba 1\u3002\u53ea\u6709\u7576\u5169\u500b\u76f8\u61c9\u7684\u4f4d\u90fd\u70ba 1 \u6642\uff0c\u7d50\u679c\u624d\u70ba 1\u3002<\/p>\n<pre><code>SELECT 5 &amp; 3 AS Result; -- \u7d50\u679c\u70ba 1 (0101 &amp; 0011 = 0001)<\/code><\/pre>\n<h3 id=\"%e4%bd%8d%e6%88%96%e9%81%8b%e7%ae%97%e7%ac%a6%ef%bc%88or%ef%bc%89-IwyXdCEmDn\">\u4f4d\u6216\u904b\u7b97\u7b26\uff08OR\uff09<\/h3>\n<p>\u4f4d\u6216\u904b\u7b97\u7b26\u7528\u65bc\u6aa2\u67e5\u5169\u500b\u6578\u5b57\u7684\u76f8\u540c\u4f4d\u662f\u5426\u81f3\u5c11\u6709\u4e00\u500b\u70ba 1\u3002\u53ea\u8981\u6709\u4e00\u500b\u4f4d\u70ba 1\uff0c\u7d50\u679c\u5c31\u70ba 1\u3002<\/p>\n<pre><code>SELECT 5 | 3 AS Result; -- \u7d50\u679c\u70ba 7 (0101 | 0011 = 0111)<\/code><\/pre>\n<h3 id=\"%e4%bd%8d%e7%95%b0%e6%88%96%e9%81%8b%e7%ae%97%e7%ac%a6%ef%bc%88xor%ef%bc%89-IwyXdCEmDn\">\u4f4d\u7570\u6216\u904b\u7b97\u7b26\uff08XOR\uff09<\/h3>\n<p>\u4f4d\u7570\u6216\u904b\u7b97\u7b26\u7528\u65bc\u6aa2\u67e5\u5169\u500b\u6578\u5b57\u7684\u76f8\u540c\u4f4d\u662f\u5426\u4e0d\u540c\u3002\u5982\u679c\u5169\u500b\u4f4d\u4e0d\u540c\uff0c\u7d50\u679c\u70ba 1\uff1b\u5982\u679c\u76f8\u540c\uff0c\u7d50\u679c\u70ba 0\u3002<\/p>\n<pre><code>SELECT 5 ^ 3 AS Result; -- \u7d50\u679c\u70ba 6 (0101 ^ 0011 = 0110)<\/code><\/pre>\n<h3 id=\"%e4%bd%8d%e9%9d%9e%e9%81%8b%e7%ae%97%e7%ac%a6%ef%bc%88not%ef%bc%89-IwyXdCEmDn\">\u4f4d\u975e\u904b\u7b97\u7b26\uff08NOT\uff09<\/h3>\n<p>\u4f4d\u975e\u904b\u7b97\u7b26\u7528\u65bc\u53cd\u8f49\u6578\u5b57\u7684\u6bcf\u4e00\u4f4d\u3002\u5373\u5c07 0 \u8b8a\u70ba 1\uff0c\u5c07 1 \u8b8a\u70ba 0\u3002<\/p>\n<pre><code>SELECT ~5 AS Result; -- \u7d50\u679c\u70ba -6 (\u53cd\u8f49 0101 \u70ba 1010)<\/code><\/pre>\n<h2 id=\"%e4%bd%8d%e9%81%8b%e7%ae%97%e7%9a%84%e5%af%a6%e9%9a%9b%e6%87%89%e7%94%a8-IwyXdCEmDn\">\u4f4d\u904b\u7b97\u7684\u5be6\u969b\u61c9\u7528<\/h2>\n<p>\u4f4d\u904b\u7b97\u5728\u8a31\u591a\u5834\u666f\u4e2d\u90fd\u975e\u5e38\u6709\u7528\uff0c\u7279\u5225\u662f\u5728\u9700\u8981\u9ad8\u6548\u5b58\u5132\u548c\u6aa2\u7d22\u72c0\u614b\u4fe1\u606f\u7684\u60c5\u6cc1\u4e0b\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u7528\u6236\u6b0a\u9650\u8868\uff0c\u6bcf\u500b\u7528\u6236\u7684\u6b0a\u9650\u53ef\u4ee5\u7528\u4e00\u500b\u6574\u6578\u4f86\u8868\u793a\uff0c\u5176\u4e2d\u6bcf\u4e00\u4f4d\u4ee3\u8868\u4e00\u7a2e\u6b0a\u9650\u3002\u9019\u6a23\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4f4d\u904b\u7b97\u4f86\u6aa2\u67e5\u7528\u6236\u662f\u5426\u64c1\u6709\u7279\u5b9a\u7684\u6b0a\u9650\u3002<\/p>\n<pre><code>DECLARE @UserPermissions INT = 5; -- 0101\nIF (@UserPermissions &amp; 1) = 1\n    PRINT '\u7528\u6236\u64c1\u6709\u6b0a\u9650 A';\nIF (@UserPermissions &amp; 2) = 2\n    PRINT '\u7528\u6236\u64c1\u6709\u6b0a\u9650 B';\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6b0a\u9650 A \u548c\u6b0a\u9650 B \u5206\u5225\u7531\u4e8c\u9032\u5236\u4f4d\u7684\u7b2c\u4e00\u4f4d\u548c\u7b2c\u4e8c\u4f4d\u8868\u793a\u3002\u901a\u904e\u4f4d\u904b\u7b97\uff0c\u6211\u5011\u53ef\u4ee5\u5feb\u901f\u6aa2\u67e5\u7528\u6236\u7684\u6b0a\u9650\uff0c\u800c\u4e0d\u9700\u8981\u4f7f\u7528\u591a\u500b\u5e03\u723e\u5b57\u6bb5\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-IwyXdCEmDn\">\u7e3d\u7d50<\/h2>\n<p>\u4f4d\u904b\u7b97\u5728 SQL Server \u4e2d\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u9ad8\u6548\u5730\u8655\u7406\u548c\u5b58\u5132\u4fe1\u606f\u3002\u901a\u904e\u4f7f\u7528\u4f4d\u904b\u7b97\u7b26\uff0c\u6211\u5011\u53ef\u4ee5\u7c21\u5316\u6578\u64da\u7684\u5b58\u5132\u7d50\u69cb\uff0c\u4e26\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\u3002\u7121\u8ad6\u662f\u5728\u7528\u6236\u6b0a\u9650\u7ba1\u7406\u9084\u662f\u5176\u4ed6\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u5834\u666f\u4e2d\uff0c\u4f4d\u904b\u7b97\u90fd\u80fd\u767c\u63ee\u91cd\u8981\u4f5c\u7528\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\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f\u5176\u4ed6\u96f2\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 SQL Server \u4e2d\u7684\u4f4d\u904b\u7b97\uff0c\u63ed\u793a\u6578\u64da\u96b1\u85cf\u7684\u79d8\u5bc6\uff0c\u63d0\u5347\u67e5\u8a62\u6548\u7387\uff0c\u512a\u5316\u6578\u64da\u8655\u7406\u6280\u5de7\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-141329","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/141329","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=141329"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/141329\/revisions"}],"predecessor-version":[{"id":141330,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/141329\/revisions\/141330"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=141329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=141329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=141329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}