Reputation: 2632
Setup: Entity framework code first to new database.
Scenario: I'm playing around with EF and I add a bunch of elements to my database. I then change the entity model, and while I know that I could do migrations, I just want to start from scratch and basically wipe the database from the earth.
The database used by default was (localdb)\v11.0.
My question is:
Can I go somewhere and just delete a file, or start some kind of manager to delete that database and start from scratch?
Upvotes: 68
Views: 57571
Reputation: 1503
If you are have either of these errors:
then check to make sure you are using the correct version of sqllocaldb.exe.
You can verify the version by using:
where.exe sqllocaldb
Which might output, for example:
C:\Program Files\Microsoft SQL Server\150\Tools\Binn\SqlLocalDB.exe
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\SqlLocalDB.exe
Depending on the order in which you install SQL Server, the newer version could be later in the path and it will report the error above.
Upvotes: 0
Reputation: 9644
I wrote a batch file to delete an SQL local db.
It uses trusted connection.
If you want, you can add your credentials with -U Username
-P Password
parameters.
Check out sqlcmd documentation!
@echo off
set /p DbName=Enter local db name:
echo.
sqlcmd -e -S "(LocalDb)\MSSQLLocalDB" -d "master" -Q "EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'%DbName%'; USE [master]; DROP DATABASE [%DbName%];"
echo Finished!
pause > nul
Upvotes: 0
Reputation: 8662
If you're using Entity Framework Core, you can enter this in the Package Manager Console:
PM> Drop-Database
It will drop the current database. This command will tell you which one:
PM> Get-DbContext
This is also handy:
PM> Get-Help about_EntityFrameworkCore
Instead of the Package Manager Console, you can also use the dotnet CLI via PowerShell or the command prompt:
PS> dotnet ef database drop
Make sure you install the EF extension first by running this command:
dotnet tool install --global dotnet-ef
Upvotes: 20
Reputation: 3937
With Entity Framework Core, this can also be accomplished form the the command line:
dotnet ef database drop --project [path to project]
Or if you have multiple database contexts:
dotnet ef database drop --project [path to project] --context [ContextName]
Make sure you install the EF extension first by running this command:
dotnet tool install --global dotnet-ef
Upvotes: 2
Reputation: 12567
There's an exe called SqlLocalDB.exe which can be found in C:\Program Files\Microsoft SQL Server\{version}\Tools\Binn
For a full delete:
>sqllocaldb stop InstanceName
>sqllocaldb delete InstanceName
Once that is done, you can optionally also remove the .mdf files from the disk. Mine were at
C:\Users\{username}
You can also recreate a fresh instance, and even attach the .mdf files you still want afterwards.
>sqllocaldb create InstanceName
>sqllocaldb start InstanceName
>sqllocaldb info InstanceName
You can see your instances at:
C:\Users\{username}\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances
Upvotes: 7
Reputation: 289
Entity Framework 3.1:
Drop Database
dotnet ef database drop
Do not want to drop database, willing to delete tables in the database
dotnet ef database update 0
Upvotes: 0
Reputation: 11274
Yes you can. In VS 2015/2017 press Ctrl+Q, type "object explorer". The "SQL Server Object Explorer" should open, where you'll see your local DB instances. Expand the DB instance, and you'll see the different databases. Select one database perform a right click and choose "Delete".
For additional information check this link.
Hope that helps.
Upvotes: 4
Reputation: 1447
Just go in command prompt with admin rights and type:
//list the instancies
sqllocaldb i
//stop selected instance
sqllocaldb p "selected instance"
//delete
sqllocaldb d "selected instance"
//recreate or create new one
sqllocaldb c "new instance"
Upvotes: 76
Reputation: 11
LocalDB is its own separate server (its name suggests that it is just a database in some other server instance but this is not the case). In SQL Server 2014 Express you connect to it using server name "(localdb)\MSSQLLocalDB", just as you would connect to any ordinary database server. If you connect using SQL Server Management Studio then you have all the power of SSMS available to you.
Upvotes: 1
Reputation: 381
From Visual Studio => Click View => SQL Server Object Explorer=> Right click the desired database and choose delete and it will be deleted or do whatever you want
Upvotes: 28
Reputation: 280351
I think you want to delete an individual database, not a LocalDB instance. If so, just issue a drop database command:
DROP DATABASE databasename;
You can do this from sqlcmd
, Management Studio, your application code, maybe even Visual Studio...
Upvotes: 9