snipt

Ctrl+h for KB shortcuts

SQL

List Sql Server Sessions

1
2
3
4
5
select 	min(login_time) as logintime, loginame, hostname, program_name, 
        db.Name as "database_name" 
	from master.dbo.sysprocesses inner join master.dbo.sysdatabases as db
	on master.dbo.sysprocesses.dbid = db.dbid
	group by loginame, hostname, program_name,db.name  order by loginame
https://snipt.net/embed/5254ebc680729079a34d8ab57654926c/
https://snipt.net/raw/5254ebc680729079a34d8ab57654926c/
5254ebc680729079a34d8ab57654926c
sql
SQL
5
2016-09-26T23:26:13
True
False
False
/api/public/snipt/11990/
list-sql-server-sessions
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">select</span> <span class="k">min</span><span class="p">(</span><span class="n">login_time</span><span class="p">)</span> <span class="k">as</span> <span class="n">logintime</span><span class="p">,</span> <span class="n">loginame</span><span class="p">,</span> <span class="n">hostname</span><span class="p">,</span> <span class="n">program_name</span><span class="p">,</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">db</span><span class="p">.</span><span class="n">Name</span> <span class="k">as</span> <span class="ss">&quot;database_name&quot;</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">from</span> <span class="n">master</span><span class="p">.</span><span class="n">dbo</span><span class="p">.</span><span class="n">sysprocesses</span> <span class="k">inner</span> <span class="k">join</span> <span class="n">master</span><span class="p">.</span><span class="n">dbo</span><span class="p">.</span><span class="n">sysdatabases</span> <span class="k">as</span> <span class="n">db</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">on</span> <span class="n">master</span><span class="p">.</span><span class="n">dbo</span><span class="p">.</span><span class="n">sysprocesses</span><span class="p">.</span><span class="n">dbid</span> <span class="o">=</span> <span class="n">db</span><span class="p">.</span><span class="n">dbid</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">group</span> <span class="k">by</span> <span class="n">loginame</span><span class="p">,</span> <span class="n">hostname</span><span class="p">,</span> <span class="n">program_name</span><span class="p">,</span><span class="n">db</span><span class="p">.</span><span class="n">name</span> <span class="k">order</span> <span class="k">by</span> <span class="n">loginame</span> </span></pre></div> </td></tr></table>
"sql server", sql
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.