declare @dbid int set @dbid=db_id('dbName') select distinct hostname, db_name(dbid), net_address, loginame, program_name from master..sysprocesses where hostname!=''and(@dbid is null or dbid=@dbid)
查询结果: