sqlserver下Kill 所有连接到某一数据库的连接

复制代码 代码如下:USE masterDECLARE @spid
intDECLARE CUR CURSORFOR SELECT spid FROM sysprocesses WHERE dbid =
5FETCH NEXT FROM CUR INTO @spidWHILE @@FETCH_STATUS = 0BEGIN–EXEC
(‘KILL ‘ + @spid )FETCH NEXT FROM CUR INTO @spidENDCLOSE CURDEALLOCATE
CUR

是游标里面嵌套游标吗?数据量大的话最好不要采用这种方法!
这是SQL SERVER的:
DECLARE CUR_1 CURSOR–第一层游标声明
FOR SELECT C_1,C_2 FROM TABLENAME
OPEN CUR_1
FETCH NEXT FROM CUR_1 INTO @C_1,@C_2
WHILE @@FETCH_STATUES<>0
BEGIN
    DECLARE CUR_2 CURSOR–第二层游标声明
    FOR SELECT A_1,A_2 FROM TABLENAME
    OPEN CUR_2
    FETCH NEXT FROM CUR_2 INTO @C_1,@C_2
    WHILE @@FETCH_STATUES<>0
    BEGIN
        …..
        …..
        FETCH NEXT FROM CUR_2 INTO @A_1,@A_2–二层循环
    END
    CLOSE CUR_2
    DEALLOCATE CUR_2
FETCH NEXT FROM CUR_1 INTO @C_1,@C_2–一层循环    
END
CLOSE CUR_1
DEALLOCATE CUR_1

查是哪个进程死锁了哪些表

 

select request_session_id
spid,OBJECT_NAME(resource_associated_entity_id) tableName
from sys.dm_tran_locks where resource_type=’OBJECT’