Microsoft offers various editions of its SQL Server product. We will use a free version that can run stand-alone, known as LocalDb. The latest version of LocalDb is installed as part of Visual Studio 2017.
When you write code to connect to a SQL Server database, you need to know its server name. The name depends on the version you choose to use. Here are some examples:
(localdb)mssqllocaldb
(localdb)mssqllocaldb
(localdb)v11.0
.sqlexpress
In Visual Studio 2017, go to File | Open | File... or press Ctrl + O .
Browse to select the Northwind.sql
file and choose Open.
In the editor window, right-click and choose Execute... or press Ctrl + Shift + E.
In the dialog box, enter the server name as (localdb)mssqllocaldb
and click on Connect, as shown in the following screenshot:
When you see the Command(s) completed successfully message, then the Northwind database has been created, and we can connect to it.
In Visual Studio 2017, choose View | Server Explorer... or press Ctrl + W, L.
In the Server Explorer window, right-click on Data Connections and choose Add Connection...
If you see the Choose Data Source dialog, as shown in the following screenshot, then select Microsoft SQL Server and click on Continue:
In the Add Connection dialog box, enter the server name as (localdb)mssqllocaldb
, enter the database name as Northwind
, and click on OK, as shown in the following screenshot:
In the Server Explorer window, expand the data connection and its tables. You should see a dozen tables, including the Products table, as shown in the following screenshot:
Right-click on the Products table and choose Show Table Data, as shown in the following screenshot:
To see the details of the Products table columns and types, right-click on Products and choose Show Table Definition, as shown in the following screenshot:
3.141.38.121