天天看点

SQL语句取得当前SQL Server已连接的数据库和用户以及所有数据库信息

SQL语句取得当前SQL Server已连接的数据库和用户 

select dbname=case  

  when dbid=0 then null  

  when dbid<>0 then db_name(dbid)  

  end, loginame from master..sysprocesses where hostname is not null

  group by dbid,loginame

所有数据库信息

select * from master.dbo.sysdatabases