Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I recently installed Microsoft SQL Server 2012 Express and I have added some databases which are blank. I would like to delete these custom databases and keep only those that came with the installation (if any).

Does anyone know how to take it back to the original, default settings or which databases within the Database I should delete / keep?

Thanks

What I have tried:

Tried to remember what I did manually.
Posted
Updated 2-Aug-18 6:23am
v2
Comments
CHill60 2-Aug-18 11:01am    
Download Sql Server Management Studio (it's free) - you can then easily see everything in your SQL server instance and remove stuff with right-click, delete

1 solution

There is more to it than deleting the DBs that you created; there are all of the server principals (users) as well.

As @CHill60 suggested, SSMS would be the best tool to get and then you can delete away on an as needed basis.

You can retrieve a list of all databases not created by SA (System Administrator) by using
SQL
SELECT [Name] FROM sys.databases where owner_sid <> 0x01

You can delete a DB via code as well
SQL
DROP DATABASE [DatabaseName]

There is a similar query for the server-principals, and a similar DROP command

Experienced SQL Users could right a quick cursor and utilize Execute sp_ExecuteSql to do this, but I would highly recommend against it
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900