Professional Documents
Culture Documents
THIS TOPIC APPLIES TO: SQL Server Azure SQL Database Azure SQL Data Warehouse Parallel Data
Warehouse
The SQL Server Management Studio (SSMS) tutorial introduces you to the integrated environment for managing
your SQL Server infrastructure. SQL Server Management Studio presents a graphical interface for configuring,
monitoring, and administering instances of SQL Server. It also allows you to deploy, monitor, and upgrade the
data-tier components used by your applications, such as databases. SQL Server Management Studio also provides
Transact-SQL, MDX, DMX, and XML language editors for editing and debugging scripts.
Requirements
This tutorial is intended for experienced database administrators and database developers who are not familiar
with Visual Studio, but who are familiar with database concepts and Transact-SQL.
You must have the following installed to use this tutorial:
Install the latest version of SQL Server Management Studio (SSMS).
The first section walks you through creating a database but other sample databases can be found here:
AdventureWorks Sample Databases. Instructions for restoring databases in SSMS can be found here: Restoring a
Database.
See Also
Database Engine Tutorials
Tutorial: Connect and Query SQL Server using SQL
Server Management Studio
3/29/2018 • 5 min to read • Edit Online
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:
Connect to a SQL Server
Create a new database (TutorialDB)
Create a table (Customers) in your new database
Insert rows into your new Customers table
Query the Customers table and view the results
Use the query window table to verify your connection properties
Change which server your query window is connected to
Prerequisites
To complete this Tutorial, you need SQL Server Management Studio and access to a SQL Server.
Install SQL Server Management Studio.
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!):
Windows - Download SQL Server 2017 Developer Edition
macOS - Download SQL Server 2017 on Docker
a. In the Connect to Server dialog box, fill out your connection options:
Server type: Database Engine (typically selected by default).
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.
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.
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.
3. Once the fields have been filled out, click on Connect.
4. You can verify that your connection succeeded to your SQL Server by exploring the objects in Object
Explorer:
Create a database
The following steps create a database named TutorialDB.
1. Right-click your server in Object Explorer and select New Query:
2. Paste the following T-SQL code snippet into the query window:
USE master
GO
IF NOT EXISTS (
SELECT name
FROM sys.databases
WHERE name = N'TutorialDB'
)
CREATE DATABASE [TutorialDB]
GO
Create a Table
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.
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.
2. Paste the following T-SQL code snippet into the query window, highlight it, and click Execute (or press F5
on your keyboard):
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.
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.
Insert rows
The following step will insert some rows into the Customers table that was previously created.
Paste the following T-SQL code snippet into the query window and click Execute:
-- Insert rows into table 'Customers'
INSERT INTO dbo.Customers
([CustomerId],[Name],[Location],[Email])
VALUES
( 1, N'Orlando', N'Australia', N''),
( 2, N'Keith', N'India', N'keith0@adventure-works.com'),
( 3, N'Donna', N'Germany', N'donna0@adventure-works.com'),
( 4, N'Janet', N'United States', N'janet1@adventure-works.com')
GO
2. The results of the query are displayed under the area where text was entered:
3. You can modify the way results are presented by selecting one of these options:
By default, the results will be in Grid View, which is the middle button and shows the results in a table.
The first button will display your results in Text View, as shown in the image in the next section.
The third button will allow you to save your results to a file, a file ending in *.rpt by default.
This tutorial will teach you how to generate Transact-SQL (T-SQL) scripts for various objects found within SQL
Server Management Studio. In this tutorial, you will find examples of how to script the following objects:
Queries when performing actions within the GUI
Databases in two different ways ("Script As" and "Generate Script")
Tables
Stored procedures
Extended events
The summary of this tutorial is that any object in Object Explorer can be scripted by right-clicking on it and
selecting the Script Object As option.
Prerequisites
To complete this Tutorial, you need SQL Server Management Studio, access to a SQL Server, and an
AdventureWorks database.
Install SQL Server Management Studio.
Install SQL Server 2017 Developer Edition.
Download an AdventureWorks Sample Databases. Instructions for restoring databases in SSMS can be found
here: Restoring a Database.
4. Open a New Query window and paste (Right click in the window > Paste):
Script Databases
The following section teaches you how to script out the database, both using the Script As option and the
Generate Scripts option. The Script As option will recreate the database and the configuration options for it. The
Generate Scripts option will script out all of the objects in the database, but not the data. To script the data as well,
you will need to you use the Import and Export Wizard.
Script database using Script option
1. Connect to your SQL Server.
2. Expand the Databases node.
3. Right-click the database > Script Database As:
4. Select Next and you'll see that you can choose to script out the entire database, or specific objects within the
database:
5. Select Next. This screen is where you can configure where the script will be saved.
You can also configure advanced options by selecting Advanced:
6. Once you're ready to proceed, keep hitting Next until the scripts are generated and you get to the Finish.
Your database script will be located where it was saved in Step 5.
This will script out the schema and various objects within the database, but not the data.
Script Tables
This section covers how to script out tables from your database.
1. Connect to your SQL Server.
2. Expand your Databases node.
3. Expand your AdventureWorks database node.
4. Expand your Tables node.
5. Right-click the table you want to script out > Script Table as:
From here, there are various options such as creating the table, or inserting data into it:
This tutorial will introduce you to the pre-built Transact-SQL (T-SQL) templates that are available within SQL Server
Management Studio (SSMS). In this article, you will learn how to:
Use the Template Browser to generate T-SQL Scripts
Edit an existing Template
Locate the templates on disk
Create a new Template
Prerequisites
To complete this Tutorial, you need SQL Server Management Studio, and access to a SQL Server.
Install SQL Server Management Studio.
Install SQL Server 2017 Developer Edition.
4. Right-click the newly created Custom Templates folder > New > Template > name your template:
5. Right-click the template you just created > Edit. This will open a New Query Window.
6. Type in the T-SQL text you want to save.
7. Save the file by going to the File menu > Save.
8. Close the existing Query Window and open your new custom template.
Next steps
The next article will provide some additional tips and tricks for using SQL Server Management Studio.
Advance to the next article to learn more
Next steps button
Tutorial: SQL Server Management Studio
Components and Configuration
3/21/2018 • 3 min to read • Edit Online
This Tutorial describes the different window components within SQL Server Management Studio (SSMS) and some
basic configuration options for your workspace. In this article, you will learn how about:
The different components that make up the SSMS environment
Changing the environmental layout and resetting it to default
Maximizing the query editor
Changing the font
Configuring startup options
Resetting the configuration back to default
Prerequisites
To complete this Tutorial, you need SQL Server Management Studio.
Install SQL Server Management Studio.
Query Window (Ctrl+N): Once you've clicked on New Query, this is the window where you will type in
your Transact-SQL (T-SQL) queries. Results of your queries are visible here as well.
Properties (F4): This is visible once the Query Window is open and displays basic properties of the query.
For example, it will show the time a query started, the number of rows returned, and connection details.
Template Browser (Ctrl+Alt+T): There are a number of pre-built T-SQL Templates that can be found in the
template browser. These templates allow you to perform various functions such as creating or backing up a
database.
Object Explorer Details(F7): This is a more granular view of what's visible in the Object Explorer, and
allows you to manipulate multiple objects at once. For example, the Object Explorer Details window allows
you to select multiple databases simultaneously and either delete them or script them out.
Change the Environmental Layout
This section discusses manipulating the environmental layout, such as moving the various windows around.
Each window component can be moved around by holding down the title and dragging the window around.
Each window component can be pinned and unpinned by selecting the pushpin icon in the title bar:
Each window component has a drop-down arrow that allows for the window to be manipulated in various
ways:
Once you have two or more query windows open, they can be tabbed vertically or horizontally so that both
query windows are visible at once. To achieve this, right-click the title of the query and select the desired
tabbed option.
This is the Horizontal Tab Group:
To restore the default environmental layout, click on the Window Menu > Reset Window Layout:
The highlighted toolbar can be modified by going to the menu: Tools > Customize:
Next steps
The next article will teach you some additional tips and tricks for using SSMS, such as finding your SQL Server error
log and your SQL instance name.
Advance to the next article to learn more
Next steps button
Tutorial: Additional Tips and Tricks for using SSMS
3/29/2018 • 5 min to read • Edit Online
This tutorial will provide you with some additional tricks for using SQL Server Management Studio. This article will
teach you how to:
Comment / Uncomment your Transact-SQL (T-SQL) text
Indent your text
Filter Objects in Object Explorer
Access your SQL Server Error log
Find the name of your SQL Server Instance
Prerequisites
To complete this Tutorial, you need SQL Server Management Studio, access to a SQL Server, and an
AdventureWorks database.
Install SQL Server Management Studio.
Install SQL Server 2017 Developer Edition.
Download an AdventureWorks Sample Databases. Instructions for restoring databases in SSMS can be found
here: Restoring a Database.
USE master
GO
5. Highlight the Alter Database portion of the text and click Comment in the toolbar:
6. Click Execute to run the uncommented portion of the text.
7. Highlight everything other than the Alter Database command and click Comment in the toolbar:
8. Highlight the Alter Database portion and click Uncomment to uncomment it:
9. Click Execute to run the uncommented portion of the text.
USE master
GO
3. Highlight the Alter Database portion of the text and press Increase Indent in the toolbar to move this text
forward:
4. Highlight the Alter Database portion of the text again and this time click Decrease Indent to move this
text back.
Filter Objects in Object Explorer
When a database has many objects, finding a specific object can prove difficult. To make this easier, you have the
ability to filter objects. This section explains how to filter tables, but the same steps can be applied to any other
node within Object Explorer
1. Connect to your SQL Server.
2. Expand your Databases node.
3. Expand your AdventureWorks database node.
4. Expand your Tables node.
You'll notice that you can see all the tables that are present in the database.
5. Right Click the Tables node > Filter > Filter Settings:
6. In the Filter Settings window, you can modify filter settings. A few examples:
Filter by name:
Filter by schema:
4. The results show you the location of the error log within the file system:
The format of the name is 'HOSTNAME\INSTANCENAME'. If all you see is the hostname, then you've
installed the default instance, and your instance name is 'MSSQLSERVER'. When connecting to a default
instance, the hostname is all you need to type in to connect to your SQL Server.
...Once you're connected to SQL
There are three places to find which SQL Server you're connected to.
1. The name of the server will be listed in Object Explorer:
3. The name of the server will also be listed in the Properties window.
To access this open the View Menu > Properties Window:
...If you're connected to an Alias or Availability Group Listener
When you're connected to an alias or an Availability Group listener, then that's what will show up Object Explorer
and Properties. In this case, the SQL Server name may not be readily apparent, and must be queried.
1. Connect to SQL Server.
2. Open a New Query window.
3. Paste the following T-SQL Code snippet into the window:
select @@Servername
4. View the results of the query to identify the name of the SQL Server you're connected to: