Skip to content

Latest commit

 

History

History
111 lines (72 loc) · 3.07 KB

File metadata and controls

111 lines (72 loc) · 3.07 KB
title Notebooks with SQL Kernel in Azure Data Studio
description This tutorial shows how you can create and run a SQL Server notebook.
author markingmyname
ms.author maghan
ms.reviewer mikeray, alayu
ms.topic tutorial
ms.prod azure-data-studio
ms.technology
ms.custom
ms.date 03/30/2020

Create and run a SQL Server notebook

[!INCLUDESQL Server 2019]

This tutorial demonstrates how to create and run a notebook in Azure Data Studio using SQL Server.

Prerequisites

New notebook

The following steps show how to create a notebook file in Azure Data Studio:

  1. In Azure Data Studio, connect to your SQL Server.

  2. Select under the Connections in the Servers window. Then select New Notebook.

    Open notebook

  3. Wait for the Kernel and the target context (Attach to) to be populated. Confirm that the Kernel is set to SQL, and set Attach to for your SQL Server (in this case its localhost).

    Set Kernel and Attach to

Run a notebook cell

You can run each notebook cell by pressing the play button to the left of the cell. The results are shown in the notebook after the cell finishes running.

Code

Add a new code cell by selecting the +Code command in the toolbar.

Notebook toolbar

This example creates a new database.

USE master
GO

   -- Drop the database if it already exists
IF  EXISTS (
        SELECT name
        FROM sys.databases
        WHERE name = N'TestNotebookDB'
   )
DROP DATABASE TestNotebookDB
GO

-- Create the database
CREATE DATABASE TestNotebookDB
GO

Run notebook cell

If you run a script that returns a result, you can save that result in different formats.

  • Save As CSV
  • Save As Excel
  • Save As JSON
  • Save As XML

In this case, we return the result of PI.

SELECT PI() AS PI;
GO

Run notebook cell

Text

Add a new text cell by selecting the +Text command in the toolbar.

Notebook toolbar

The cell changes to edit mode and now type markdown and you can see the preview at the same time

Markdown cell

Selecting outside the text cell shows the markdown text.

Markdown text

Next steps

Learn more about notebooks: