You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Title: "Tutorial: Connect and Query SQL Server using SQL Server Management Studio"
3
-
description: A Tutorial for connecting to SQL Server using SQL Server Management Studio and running basic T-SQL queries.
2
+
Title: "Tutorial: Connect to and query a SQL Server instance by using SQL Server Management Studio"
3
+
description: A tutorial for connecting to a SQL Server instance by using SQL Server Management Studio and running basic T-SQL queries.
4
4
keywords: SQL Server, SSMS, SQL Server Management Studio
5
5
author: MashaMSFT
6
6
ms.author: mathoma
@@ -12,63 +12,62 @@ ms.reviewer: sstein
12
12
manager: craigg
13
13
---
14
14
15
-
# Tutorial: Connect and Query SQL Server using SQL Server Management Studio
16
-
This Tutorial teaches you how to use SQL Server Management Studio (SSMS) to connect to your SQL Server instance, and run some basic Transact-SQL (T-SQL) commands. This article demonstrates how to do the following:
17
-
18
-
> [!div class="checklist"]
19
-
> *[Connect to a SQL Server](#connect-to-a-sql-server)
20
-
> *[Create a new database (**TutorialDB**)](#create-a-database)
21
-
> *[Create a table (**Customers**) in your new database](#create-a-table)
22
-
> *[Insert rows into your new **Customers** table](#insert-rows)
23
-
> *[Query the **Customers** table and view the results](#view-query-results)
24
-
> *[Use the query window table to verify your connection properties](#verify-your-query-window-connection-properties)
25
-
> *[Change which server your query window is connected to](#change-server-connection-within-query-window)
15
+
# Tutorial: Connect to and query a SQL Server instance by using SQL Server Management Studio
16
+
This tutorial teaches you how to use SQL Server Management Studio (SSMS) to connect to your SQL Server instance and run some basic Transact-SQL (T-SQL) commands. The article demonstrates how to do the following:
26
17
18
+
> [!div class="checklist"]
19
+
> * Connect to a SQL Server instance
20
+
> * Create a database ("TutorialDB")
21
+
> * Create a table ("Customers") in your new database
22
+
> * Insert rows into your new table
23
+
> * Query the new table and view the results
24
+
> * Use the query window table to verify your connection properties
25
+
> * Change the server that your query window is connected to
27
26
28
27
## Prerequisites
29
-
To complete this Tutorial, you need SQL Server Management Studio and access to a SQL Server.
28
+
To complete this tutorial, you need SQL Server Management Studio and access to a SQL Server instance.
30
29
31
30
- Install [SQL Server Management Studio](https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms).
32
31
33
-
If you don't have access to a SQL Server, select your platform from the following links (make sure you remember your SQL Login and Password if you choose SQL Authentication!):
34
-
-[Windows - Download SQL Server 2017 Developer Edition](https://www.microsoft.com/en-us/sql-server/sql-server-downloads)
35
-
-[macOS - Download SQL Server 2017 on Docker](https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker)
32
+
If you don't have access to a SQL Server instance, select your platform from the following links. If you choose SQL Authentication, use your SQL Server login credentials.
33
+
-**Windows**: [Download SQL Server 2017 Developer Edition](https://www.microsoft.com/en-us/sql-server/sql-server-downloads).
34
+
-**macOS**: [Download SQL Server 2017 on Docker](https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker).
36
35
37
36
38
-
## Connect to a SQL Server
37
+
## Connect to a SQL Server instance
39
38
40
-
1. Start SQL Server Management Studio (SSMS).
41
-
1. The first time you run SSMS the **Connect to Server** dialog box opens.
42
-
- If the **Connect to Server** dialog doesn't open, it can be opened manually in **Object Explorer** > **Connect** (or icon next to it) > **Database Engine**.
39
+
1. Start SQL Server Management Studio.
40
+
The first time you run SSMS, the **Connect to Server** window opens. If it doesn't open, you can open it manually by selecting **Object Explorer** > **Connect** > **Database Engine**.
43
41
44
-

42
+

45
43
46
-
1. In the **Connect to Server**dialog box, fill out your connection options:
44
+
2. In the **Connect to Server**window, do the following:
47
45
48
-
- **Server type**: Database Engine (typically selected by default).
49
-
- **Server Name**: This article uses the instance name SQL2016ST on the hostname NODE5 (NODE5\SQL2016ST), but you'll need to type in your own server name here. If you're not sure how to determine your SQL Server name, you can find more information [here](ssms-tricks.md#determine-sql-server-name).
50
-
- **Authentication**: Windows Authentication (this article uses Windows Authentication, but SQL Login is supported and will prompt you for a username and password if selected). More information on authentication types can be found [here](https://docs.microsoft.com/en-us/sql/ssms/f1-help/connect-to-server-database-engine).
46
+
- For **Server type**, select **Database Engine** (usually the default option).
47
+
- For **Server name**, enter the name of your SQL Server instance. (This article uses the instance name SQL2016ST on the hostname NODE5 [NODE5\SQL2016ST].) If you're unsure how to determine your SQL Server instance name, see [Additional tips and tricks for using SSMS](ssms-tricks.md#determine-sql-server-name).

53
50
54
-
You can also modify additional connection options (such as the database you're connecting to, the connection timeout value, and the network protocol) by clicking the **Options** button. For the purpose of this article, everything was left at the default values.
51
+

55
52
53
+
- For **Authentication**, select **Windows Authentication**. This article uses Windows Authentication, but SQL Server login is also supported. If you select **SQL Login**, you will be prompted for a username and password. For more information about authentication types, see [Connect to server (database engine)](https://docs.microsoft.com/en-us/sql/ssms/f1-help/connect-to-server-database-engine).
56
54
57
-
1. Once the fields have been filled out, click on **Connect**.
55
+
You can also modify additional connection options by selecting **Options**. Examples of connection options are the database you're connecting to, the connection timeout value, and the network protocol. This article uses the default values for all the options.
58
56
59
-
1. You can verify that your connection succeeded to your SQL Server by exploring the objects in**Object Explorer**:
57
+
3. After you've completed all the fields, select**Connect**.
After the query completes, the new **TutorialDB** appears in the list of databases within **Object Explorer**. If you don’t see it, right-click the Databases node and select **Refresh**.
86
+
After the query is complete, the new TutorialDB database appears in the list of databases in Object Explorer. If it isn't displayed, right-click the **Databases** node, and then select **Refresh**.
89
87
90
88
91
-
## Create a Table
92
-
The following steps will now create a table in the newly created **TutorialDB** database. However, the query editor is still in the context of the *master* database, and you want to create a table in the *TutorialDB* database.
89
+
## Create a table in the new database
90
+
In this section, you create a table in the newly created TutorialDB database. Because the query editor is still in the context of the *master* database, switch the connection context to the *TutorialDB* database by doing the following:
93
91
94
-
1.Change the connection context of your query from the master database to **TutorialDB** by selecting the database you want from the database drop-down.
92
+
1.In the database drop-down list, select the database that you want, as shown here:
1. Paste the following T-SQL code snippet into the query window, highlight it, and click **Execute** (or press F5 on your keyboard):
99
-
-You can either replace the existing text in the query window or append it to the end. If you want to execute everything in the query window, click**Execute**. If you want to execute a portion of the text, highlight that portion, and then click**Execute**.
96
+
2. Paste the following T-SQL code snippet into the query window, select it, and then select**Execute** (or select F5 on your keyboard).
97
+
You can either replace the existing text in the query window or append it to the end. To execute everything in the query window, select**Execute**. To execute a portion of the text, highlight that portion, and then select**Execute**.
100
98
101
99
```sql
102
100
-- Create a new table called 'Customers' in schema 'dbo'
@@ -114,12 +112,11 @@ The following steps will now create a table in the newly created **TutorialDB**
114
112
);
115
113
GO
116
114
```
117
-
After the query completes, the new **Customers** table appears in the list of tables in **Object Explorer**. If the table is not visible, right-click the **TutorialDB > Tables** node in **Object Explorer** and select **Refresh**.
118
115
119
-
## Insert rows
120
-
The following step will insert some rows into the **Customers** table that was previously created.
116
+
After the query is complete, the new Customers table is displayed in the list of tables in Object Explorer. If the table is not displayed, right-click the **TutorialDB** > **Tables** node in Object Explorer, and then select **Refresh**.
121
117
122
-
Paste the following T-SQL code snippet into the query window and click **Execute**:
118
+
## Insert rows into the new table
119
+
Insert some rows into the Customers table that you created previously. To do so, paste the following T-SQL code snippet into the query window, and then select **Execute**:
123
120
124
121
125
122
```sql
@@ -134,44 +131,49 @@ Paste the following T-SQL code snippet into the query window and click **Execute
134
131
GO
135
132
```
136
133
137
-
## View Query Results
138
-
The results of a query are visible underneath the query text window. The below steps will allow you to query the **Customers** table and view the rows that were previously inserted.
134
+
## Query the table and view the results
135
+
The results of a query are visible below the query text window. To query the Customers table and view the rows that were previously inserted, do the following:
139
136
140
-
1. Paste the following T-SQL code snippet into the query window and click**Execute**:
137
+
1. Paste the following T-SQL code snippet into the query window, and then select**Execute**:
141
138
142
139
```sql
143
140
-- Select rows from table 'Customers'
144
141
SELECT*FROMdbo.Customers;
145
142
```
146
-
1. The results of the query are displayed under the area where text was entered:
- The middle button displays the results in **Grid View**, which is the default option.
153
+
- The first button displays the results in **Text View**, as shown in the image in the next section.
154
+
- The third button lets you save the results to a file whose extension is .rpt by default.
154
155
155
-
- By default, the results will be in **Grid View**, which is the middle button and shows the results in a table.
156
-
- The first button will display your results in **Text View**, as shown in the image in the next section.
157
-
- The third button will allow you to save your results to a file, a file ending in *.rpt by default.
156
+
## Verify your connection properties by using the query window table
157
+
You can find information about the connection properties under the results of your query. After you run the previously mentioned query in the preceding step, review the connection properties at the bottom of the query window.
158
158
159
-
## Verify your query window connection properties
160
-
You can find information about the connection properties under the results of your query.
161
-
- After running the aforementioned query from the previous step, review the connection properties at the bottom of the query window.
162
-
- You can determine which server and database you're connected to, and the user you're logged in with.
163
-
- You can also see the query duration and the number of rows returned by the query executed earlier.
159
+
- You can determine which server and database you're connected to, and the username that you're logged in with.
160
+
- You can also view the query duration and the number of rows that are returned by the previously executed query.
0 commit comments