UseMasterGoDeclare @dbName nvarchar( -)Set @dbName='Supervise_changchun' --Database nameDeclare @spid nvarchar( -) DeclareCur_lockcursor for SELECT DISTINCTrequest_session_id fromMaster.sys.dm_tran_locksWHEREResource_type= 'DATABASE' andresource_database_id= db_id(@dbName)OpenCur_lockFetchCur_lock into @spid while @ @fetch_status=0 begin exec('Kill'+@spid) Fetch Next fromCur_lock into @spidEnd CloseCur_lockdeallocateCur_lock
Use Master
Go
Declare @dbName nvarchar (+)
Set@dbName='Supervise_changchun'--Database name
declare @spid nvarchar ( 20 )
Declare Cur_lock cursor for
selectdistinctrequest_session_id fromMaster.sys.dm_tran_locksWHEREResource_type= ' DATABASE ' andresource_database_id= db_id(@dbName)
Open Cur_lock
fetch cur _lock into @spid
while @ @fetch_status = 0
Begin
exec ( ' Kill ' + @spid )
Fetchnext from Cur_lock into @spid
End
Close Cur_lock
deallocate Cur_lock
de-SQL Server database usage