Wednesday, November 28, 2012

Unable to restore database in SQL Server because of running processes

Unable to restore database in SQL Server because of running processes.

If you are unable to restore database in SQL Server because of running processes.

1. You can find which processes are running using the following command:
sp_who2

2. After finding out which processes are running relating to the particular database, you can kill them using the kill command with process id

For eg.

kill 63
kill 55

This should restore your database.


Thursday, November 15, 2012

Delete duplicate rows in table with no key in SQL Server

Delete duplicate rows in table with no key in SQL Server:

DELETE
FROM  TableName
WHERE TableName.%%physloc%%
      NOT IN (SELECT MIN(b.%%physloc%%)
              FROM TableName b
              GROUP BY b.ColumnName)