In some samples of the book, we use a SQL Server database. To install a SQL Server database, we can either attach the SQL Server MDF file to SQL Server or execute a SQL query file that contains the commands to create the database, its tables, and its columns.
The simplest way to install a database is attaching the database into the SQL Server instance. To do so, follow the given steps:
1. Open SQL Server Management Studio and connect to the database engine (most of the time, this instance is called localhost).
2. Within the Object Explorer, right-click on the Databases node and select Attach.
3. In the Attach Databases dialog, click on the Add button and browse to the location of the MDF file that contains the database. Click OK; SQL Server will now attach the database to the SQL Server instance.
The database can now be consulted from within SQL Server Management Studio and it can also be used in our own applications.
If attaching the database is not an option (for example, on an externally hosted database server), we can use a query file that contains all the commands needed to recreate the database and its tables. To do so, follow the next steps:
1. Open SQL Server Management Studio and connect to the database engine (usually localhost).
2. Within Management Studio, select File | Open File and select the query file (
*.sql
) containing the SQL commands.3. Click on Execute.
Management Studio will now execute the commands, resulting in the database being created.