/ Published in: SQL
                    
                                        
Kill connections to a database to perform maintenance that requires a connectionless DB
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
1) GET the processes attached TO that DATABASE:
SELECT spid FROM master..sysprocesses WHERE dbid = DB_ID(@DatabaseName)
AND spid != @@SPID
Note : @@SPID IS your connected instance Service Process id "SPID"
2) Perform KILL operation IN a loop OR USE cursor
EXEC('KILL '+RTRIM(@spid) )
Comments
 Subscribe to comments
                    Subscribe to comments
                
                