--数据库当前能接受的最大连接数
select @@MAX_CONNECTIONS
--查询所有数据库当前的连接数
sp_who
--查询指定数据库的当前连接数
SELECT * FROM
[Master].[dbo].[SYSPROCESSES] WHERE [DBID]
IN
(
SELECT
[DBID]
FROM
[Master].[dbo].[SYSDATABASES]
WHERE
NAME='fdaysmanygoods'
)
--关闭指定数据库的所有连接
use master
declare @spid int,@str varchar(100),@dbid int,@dbname varchar(255)
set @dbname= 'fdaysmanygoods '
select @dbid=dbid from master.dbo.sysdatabases WHERE name = @dbname
declare cur_spid cursor local for
select spid from master.dbo.sysprocesses where
dbid=@dbid
open cur_spid
fetch from cur_spid into @spid
while @@fetch_status=0
begin
set @str= 'kill '+Cast(@spid as varchar(10))
exec(@str)
fetch from cur_spid into @spid
end
close cur_spid
deallocate cur_spid