Tuesday, 7 August 2018 By Fred Mintah
Creating a new or attaching a database
Once you have established connection to your LocalDB server, you may want to attached an existing database files or create new ones.(If you don't know how to connect to the LocalDB, please follow this link Connecting to Microsoft SQL Server LocalDB )
To do this, you have a number of options.
- Create a new database
- Attached existing database files (graphical and scripting)
- Restore a backup file
Creating a new database
Right-Click on the Databases tree in Management Studio and select New Database
Enter the name of the database (1) and choose the location to save it (2)
Attached existing database files (scripting)
- Locate the location hosting the database files
- Open New Query in SQL Management Studio
- Use the Create database syntax to attached a database
create database MyLocalDB2
on
(filename = 'C:\Temp\LocalDB\LocalDB.mdf'),
(filename = 'C:\Temp\LocalDB\LocalDB.Ldf')
for attach
Attached existing database files (Graphical view)
Right-click on Databases tree in Management studio
Select Attach…
From here, browse for the source location of the data file of the database files to be attached.
Double click ( .mdf file) to open or select, then click OK button to attach
Restore Database from a backup file
The process to restore a database file is the same as attaching a database but the extention of the restore file is a .bak file extention