SQL Server Local Database common commands
Cheat sheet for myself. There are more comprehensive guides out there.
Starting the instance
sqllocaldb start
sqllocaldb s
If you don't specify the instance name after start, it starts MSSQLLocalDB by default.
Interacting with the database
Once the database has started, you can interact with it using Invoke-Sqlcmd.
Invoke-Sqlcmd
-ServerInstance "(localdb)\<instancename>"
-Database "<databasename>"
-Query "SELECT name FROM sys.databases"
For example,
Invoke-Sqlcmd
-ServerInstance "(localdb)\MSSQLLocalDB"
-Database "master"
-Query "SELECT name FROM sys.databases"
Creating a new database
This is normal SQL.
CREATE DATABASE "<databasename>"
Further reading:
- (Code Project)[https://www.codeproject.com/articles/Devs-User-Guide-To-SqlLocalDb-Sql-Express#comments-section]