Skip to content

Commit b57e339

Browse files
committed
Refresh LocalDB article and include PR 9518
1 parent c6d3182 commit b57e339

1 file changed

Lines changed: 64 additions & 61 deletions

File tree

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,74 @@
11
---
2-
title: Build and Deploy to a Local Database
3-
description: Learn about the local server instance that SQL Server 2022 provides. See how to use this instance for building, testing, and debugging development projects.
2+
title: Build and deploy to a local database
3+
description: Learn about the local server instance that SQL Server provides. See how to use this instance for building, testing, and debugging development projects.
44
author: markingmyname
55
ms.author: maghan
6-
ms.date: 02/09/2017
6+
ms.reviewer: randolphwest
7+
ms.date: 11/30/2023
78
ms.service: sql
89
ms.subservice: ssdt
910
ms.topic: conceptual
1011
---
1112

12-
# How to: Build and Deploy to a Local Database
13+
# How to: Build and deploy to a local database
14+
15+
[!INCLUDE [ssnoversion-md](../includes/ssnoversion-md.md)] provides a local on-demand server instance, called [!INCLUDE [ssnoversion-md](../includes/ssnoversion-md.md)] Express Local Database Runtime (LocalDB), which is activated when you debug a [!INCLUDE [ssnoversion-md](../includes/ssnoversion-md.md)] Database project. This local server instance can be used as a sandbox for building, testing, and debugging your project.
16+
17+
It is independent of any of your installed [!INCLUDE [ssnoversion-md](../includes/ssnoversion-md.md)] instances, and isn't accessible outside [!INCLUDE [ssnoversion-md](../includes/ssnoversion-md.md)] Data Tools (SSDT). Such an arrangement is ideal for developers with limited or no access to production databases, but would like to test their projects locally before authorized personnel deploy them to production. In addition, when you're developing a database solution for Azure SQL, you can utilize the convenience provided by this local server to develop and test your database project locally, before deploying it to the cloud.
18+
19+
## Limitations
20+
21+
A database under the local database node in [!INCLUDE [ssnoversion-md](../includes/ssnoversion-md.md)] Object Explorer is a reflection of its corresponding database project, and isn't related to the same-named database in a connected server instance.
1322

14-
Microsoft SQL Server 2022 provides a local on-demand server instance, called SQL Server Express Local Database Runtime, which is activated when you debug a SQL Server Database project. This local server instance can be used as a sandbox for building, testing and debugging your project. It is independent of any of your installed SQL Server instances, and is not accessible outside SQL Server Data Tools (SSDT). Such an arrangement is ideal for developers who have limited or no access to production databases, but would like to test their projects locally before authorized personnel will deploy them to production. In addition, when you are developing a database solution for SQL Azure, you can utilize the convenience provided by this local server to develop and test your database project locally, before deploying it to the cloud.
15-
16-
> [!WARNING]
17-
> A database under the local database node in SQL Server Object Explorer is a reflection of its corresponding database project, and is not related to the same-named database in a connected server instance.
18-
1923
> [!WARNING]
20-
> The following procedures utilize entities created in previous procedures in the [Connected Database Development](../ssdt/connected-database-development.md) and [Project-Oriented Offline Database Development](../ssdt/project-oriented-offline-database-development.md) sections.
21-
22-
### To use the local database
23-
24-
1. Notice that in **SQL Server Object Explorer**, under the **SQL Server** node, a new node named **Local** appears. This is the local database instance.
25-
26-
2. Expand the **Local** and **Databases** nodes. Notice the appearance of a database with the same name as the TradeDev project. Expand the nodes under this database. The **Data Tools Operations** window shows the status of expansion/import operations in progress on any database in the **Local** node. Notice that they do not contain any of the tables and entities we created in earlier procedures.
27-
28-
3. Press F5 to debug the TradeDev database project.
29-
30-
By default, SSDT will use the local database server instance for debugging database projects. In this case, SSDT will first attempt to build the project, and if there is no error, the project (and its entities) will be deployed to the local database. If you debug the same project later, SSDT will detect any changes since your last debugging session, and deploy only those to the local database.
31-
32-
4. Expand the nodes under **TradeDev** in the **Local** database server again. This time, notice that the tables, views and functions have been deployed to the local database server.
33-
34-
5. Right-click the **TradeDev** node and select **New Query**.
35-
36-
6. In the script pane, paste this code and click the **Execute Query** button to run the query.
37-
38-
```
39-
select * from dbo.GetProductsBySupplier(1)
40-
```
41-
42-
7. The **Message** pane shows (0 row(s) affected), and the **Results** pane returns no row. This is because we are querying against the local database instead of the connected database that actually contains real data.
43-
44-
You can confirm this by right-clicking the **Products** table under this local **TradeDev** database, and select **View Data**. Notice that the table is empty.
45-
46-
### To replicate real data to the local database
47-
48-
1. In **SQL Server Object Explorer**, expand your connected SQL Server instance and locate the **TradeDev** database.
49-
50-
Right-click **Suppliers** table and select **View Data**.
51-
52-
2. Click the **Script** button (the second button from the right) on top of the Data Editor. Copy the `INSERT` statements from the script.
53-
54-
3. Expand the **Local** server instance and right-click the **TradeDev** node, select **New Query**.
55-
56-
4. Paste the `INSERT` statements into this query window and execute the query.
57-
58-
5. Repeat the above steps to replicate data from the **Products** and **Fruits** tables in the connected **TradeDev** database to the local **TradeDev** database.
59-
60-
6. Right-click the **Local** server instance and select **Refresh**. Examine the tables using **View Data** to verify that the local database has been populated.
61-
62-
7. Right-click the **TradeDev** node of the Local server instance, and select **New Query**.
63-
64-
8. In the script pane, paste this code and click the **Execute Query** button to run the query.
65-
66-
```
67-
select * from dbo.GetProductsBySupplier(1)
68-
```
69-
70-
9. In the **Results** pane below the Transact-SQL Editor pane, you will see that the Apples and Potato Chips rows of the `Products` table are returned.
71-
24+
> The following procedures utilize entities created in previous procedures in the [Connected Database Development](connected-database-development.md) and [Project-Oriented Offline Database Development](project-oriented-offline-database-development.md) sections.
25+
26+
## Use the local database
27+
28+
1. In **SQL Server Object Explorer**, under the **SQL Server** node, a new node named **Local** appears. This is the local database instance.
29+
30+
1. Expand the **Local** and **Databases** nodes. Notice the appearance of a database with the same name as the TradeDev project. Expand the nodes under this database. The **Data Tools Operations** window shows the status of expansion/import operations in progress on any database in the **Local** node. They don't contain any of the tables and entities we created in earlier procedures.
31+
32+
1. Press F5 to debug the TradeDev database project.
33+
34+
By default, SSDT uses the local database server instance for debugging database projects. In this case, SSDT first attempts to build the project, and if there's no error, the project (and its entities) are deployed to the local database. If you debug the same project later, SSDT detects any changes since your last debugging session, and deploy only those changes to the local database.
35+
36+
1. Expand the nodes under `TradeDev` in the **Local** database server again. This time, notice that the tables, views, and functions were deployed to the local database server.
37+
38+
1. Right-click the `TradeDev` node and select **New Query**.
39+
40+
1. In the script pane, paste this code and select the **Execute Query** button to run the query.
41+
42+
```sql
43+
SELECT * FROM dbo.GetProductsBySupplier(1);
44+
```
45+
46+
1. The **Message** pane shows `(0 row(s) affected)`, and the **Results** pane returns no rows. This is because we query against the local database, instead of the connected database that actually contains real data.
47+
48+
You can confirm this by right-clicking the `Products` table under this local `TradeDev` database, and select **View Data**. The table is empty.
49+
50+
## Replicate real data to the local database
51+
52+
1. In **SQL Server Object Explorer**, expand your connected SQL Server instance and locate the `TradeDev` database.
53+
54+
Right-click `Suppliers` table and select **View Data**.
55+
56+
1. Select the **Script** button (the second button from the right) on top of the Data Editor. Copy the `INSERT` statements from the script.
57+
58+
1. Expand the **Local** server instance and right-click the `TradeDev` node, select **New Query**.
59+
60+
1. Paste the `INSERT` statements into this query window and execute the query.
61+
62+
1. Repeat the above steps to replicate data from the `Products` and `Fruits` tables in the connected `TradeDev` database to the local `TradeDev` database.
63+
64+
1. Right-click the **Local** server instance and select **Refresh**. Examine the tables using **View Data** to verify that the local database was populated.
65+
66+
1. Right-click the `TradeDev` node of the Local server instance, and select **New Query**.
67+
68+
1. In the script pane, paste this code and select the **Execute Query** button to run the query.
69+
70+
```sql
71+
SELECT * FROM dbo.GetProductsBySupplier(1);
72+
```
73+
74+
1. In the **Results** pane below the Transact-SQL Editor pane, you see that the `Apples` and `Potato Chips` rows of the `Products` table are returned.

0 commit comments

Comments
 (0)