select distinct hostname, db_name(dbid), net_address, --物理地址 loginame, program_name from master..sysprocesses where hostname='zhc'and(db_id(db_name()) is null or dbid=db_id(db_name()) )
--查看服务器实际MAC地址
create table #(str varchar(100) null) insert # exec master..xp_cmdshell 'ipconfig /all' select * from # where isnull(str,'') <> '' drop table #
---查看当前数据库连接的数据库名称
--@@spid是当前用户进程的会话 ID --用此会话ID在Master..SysProcesses中查得当前用户进程使用的数据库ID --再用此数据库ID在查得Master..SysDataBases中查到对应的数据库名称 Select Name From Master..SysDataBases Where DbId=(Select Dbid From Master..SysProcesses Where Spid = @@spid)
或者 select DB_NAME()
--获取服务器IP地址
select local_net_address from sys.dm_exec_connections where session_id=@@spid