I have a server (SQL Server 2005) with more than 300 databases. I don't want to right-click one by one and select Delete
.
How can I delete all databases easily?
I have a server (SQL Server 2005) with more than 300 databases. I don't want to right-click one by one and select Delete
.
How can I delete all databases easily?
You can do this through the SSMS GUI. Select the
Databases
node then F7 to bring up Object Explorer Details, Select all databases that you want to delete, Hit "Delete" and select the "Close Existing Connections" and "Continue after error" options.Alternatively through TSQL you can do
And here is my solution for the same problem:
The safe way of deleting (dropping) all databases in MS-SQL using T-SQL is to exclude all system databases, and any other database(s) that you want to keep, and special databases such as Data Warehouse database "DW", Report server database.
Excluding all the databases that we want to keep including all system databases will make it safe to delete just everything else that we don't want to keep.
For example:
I used the answer provided by Pellared and modified it slightly.
I've been confronted to a problem with my databases, and the solutions above weren't working.
I simply wanted to delete all my databases, but I had a problem with their names. Indeed, I had databases named like this :
The easier way to delete these database (tested on MariaDB) is to execute the following command :
This kind of name seems to be a problem when we directly want to execute a SQL command from a bash file, because we have to specify the database's name between back quotes (``).
If you have the same problem, and if you have a lot of databases, you just have to create a batch script with all the commands you need, and then execute this one in your SQL server.
Example with test.sh :
I think that this script is working in all cases. Hope this helped.
You can use Cursor like this:
In my blog is more about this topic. www.pigeonsql.com