{"id":1080,"date":"2010-05-11T21:13:00","date_gmt":"2010-05-11T01:13:00","guid":{"rendered":""},"modified":"2013-11-24T20:35:59","modified_gmt":"2013-11-24T12:35:59","slug":"%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8bsql-server%e6%95%b0%e6%8d%ae%e5%ba%93%e5%bd%93%e5%89%8d%e8%bf%9e%e6%8e%a5%e6%95%b0","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/1080.html","title":{"rendered":"\u5982\u4f55\u67e5\u770bSQL SERVER\u6570\u636e\u5e93\u5f53\u524d\u8fde\u63a5\u6570"},"content":{"rendered":"<p>1.\u901a\u8fc7\u7ba1\u7406\u5de5\u5177<\/p>\n<p>\u5f00\u59cb-&gt;\u7ba1\u7406\u5de5\u5177-&gt;\u6027\u80fd\uff08\u6216\u8005\u662f\u8fd0\u884c\u91cc\u9762\u8f93\u5165 mmc\uff09\u7136\u540e\u901a\u8fc7\u6dfb\u52a0\u8ba1\u6570\u5668\u6dfb\u52a0 SQL \u7684\u5e38\u7528\u7edf\u8ba1 \u7136\u540e\u5728\u4e0b\u9762\u5217\u51fa\u7684\u9879\u76ee\u91cc\u9762\u9009\u62e9\u7528\u6237\u8fde\u63a5\u5c31\u53ef\u4ee5\u65f6\u65f6\u67e5\u8be2\u5230\u6570\u636e\u5e93\u7684\u8fde\u63a5\u6570\u4e86\u3002\u4e0d\u8fc7\u6b64\u65b9\u6cd5\u7684\u8bdd\u9700\u8981\u6709\u8bbf\u95ee\u90a3\u53f0\u8ba1\u7b97\u673a\u7684\u6743\u9650\uff0c\u5c31\u662f\u8981\u901a\u8fc7Windows\u8d26\u6237\u767b\u9646\u8fdb\u53bb\u624d\u53ef\u4ee5\u6dfb\u52a0\u6b64\u8ba1\u6570\u5668\u3002<\/p>\n<p>2.\u901a\u8fc7\u7cfb\u7edf\u8868\u67e5\u8be2<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSELECT * FROM\r\n&#x5B;Master].&#x5B;dbo].&#x5B;SYSPROCESSES] WHERE &#x5B;DBID] IN ( SELECT\r\n   &#x5B;DBID]\r\nFROM\r\n   &#x5B;Master].&#x5B;dbo].&#x5B;SYSDATABASES]\r\nWHERE\r\n   NAME=\u2019DBName\u2019\r\n)\r\n<\/pre>\n<p>DBName \u662f\u9700\u8981\u67e5\u770b\u7684\u6570\u636e\u5e93\uff0c\u7136\u540e\u67e5\u8be2\u51fa\u6765\u7684\u884c\u6570\uff0c\u5c31\u662f\u5f53\u524d\u7684\u8fde\u63a5\u6570\u3002\u4e0d\u8fc7\u91cc\u9762\u8fd8\u6709\u4e00\u4e9b\u522b\u7684\u72b6\u6001\u53ef\u4ee5\u505a\u53c2\u8003\u7528\u3002<\/p>\n<p>\u4f8b\u5982\uff1a\u8fde\u5230master\u8fd9\u4e2a\u6570\u636e\u5e93\u5199\u5982\u4e0b\u8bed\u53e5<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nselect * from sysprocesses where dbid in (select dbid from sysdatabases where name=\u2019MyDatabase\u2019)\r\n<\/pre>\n<p>\u5c06\u6240\u6709\u8fde\u63a5MyDatabase\u8fd9\u4e2a\u6570\u636e\u5e93\u7684\u8fde\u63a5\u8bb0\u5f55\u90fd\u6c42\u51fa\u6765\u3002<br \/>\nsysprocesses\u8fd9\u4e2a\u8868\u8bb0\u5f55\u6240\u4ee5\u8fde\u63a5\u5230SQL SERVER\u6570\u636e\u5e93\u7684\u8fde\u63a5\u3002<\/p>\n<p>3.\u901a\u8fc7\u7cfb\u7edf\u7684\u5b58\u50a8\u8fc7\u7a0b\u6765\u67e5\u627e<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSP_WHO \u2018UserName\u2019\r\n<\/pre>\n<p>UserName \u662f\u5f53\u7136\u767b\u9646Sql\u7684\u7528\u6237\u540d\uff0c\u4e00\u822c\u7a0b\u5e8f\u91cc\u9762\u90fd\u4f1a\u4f7f\u7528\u4e00\u4e2aUserName\u6765\u767b\u9646SQL\u8fd9\u6837\u901a\u8fc7\u8fd9\u4e2a\u7528\u6237\u540d\u5c31\u80fd\u67e5\u770b\u5230\u6b64\u7528\u6237\u540d\u767b\u9646\u4e4b\u540e\u5360\u7528\u7684\u8fde\u63a5\u4e86\u3002<br \/>\n\u5982\u679c\u4e0d\u5199UserName\uff0c\u90a3\u4e48\u8fd4\u56de\u7684\u5c31\u662f\u6240\u6709\u7684\u8fde\u63a5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u901a\u8fc7\u7ba1\u7406\u5de5\u5177 \u5f00\u59cb-&gt;\u7ba1\u7406\u5de5\u5177-&gt;\u6027\u80fd\uff08\u6216\u8005\u662f\u8fd0\u884c\u91cc\u9762\u8f93\u5165 mmc\uff09\u7136\u540e\u901a\u8fc7\u6dfb\u52a0\u8ba1\u6570\u5668\u6dfb\u52a0 S [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1080","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=1080"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1080\/revisions"}],"predecessor-version":[{"id":5167,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1080\/revisions\/5167"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=1080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=1080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=1080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}