Error:
Sometimes I face issues with the database deletion in the SQL server. If we have configured replication in the database previously. In that case, when I try to remove the database it gives me the following error.
Cannot drop the database ‘Test_db’ because it is being used for replication. (Microsoft SQL Server, Error: 3724) Advertisement
Solution 1:
Use the sp_removedbreplication stored procedure to remove all the replication objects on the publication and subscription databases.
Make sure to change the database name “Test_db” with your database name.
DECLARE @subscriptionDB AS sysname SET @subscriptionDB = N'Test_db' USE master EXEC sp_removedbreplication @subscriptionDB GO
After executing the above T-SQL statement, you can remove your database.
Solution 2:
Create a database with the same name on another SQL server instance. Then create a full backup of the database. Now restore the database to this server forcefully.
To restore the database forcefully, make sure to select the “WITH REPLACE” option
Now you can remove the database from the SQL Server.