sql概述_SQL Notebook简介和概述

sql概述

This article explains the SQL Notebook feature in Azure Data Studio along with the Markdown language to customize it.

本文介绍了Azure Data Studio中SQL Notebook功能以及用于自定义它的Markdown语言。

Azure Data Studio is a cross-platform tool working on both on-premises and cloud-based systems. Microsoft releases monthly releases of Azure Data Studio. These monthly features include new features, enhancements to existing features, bug fixes etc.

Azure Data Studio是可在本地和基于云的系统上运行的跨平台工具。 Microsoft每月发布Azure Data Studio。 这些每月的功能包括新功能,对现有功能的增强,错误修复等。

Microsoft released the latest release of Azure Data Studio 1.7.0 on May 8, 2019. You can download installer on a platform of your choice and install it.

Microsoft已于2019年5月8日发布了最新版本的Azure Data Studio 1.7.0 。您可以在所选平台上下载安装程序并进行安装。

Download and install Azure Data Studio May Release

In the March release, Microsoft released new feature called SQL Notebook. Let’s explore this feature in this article.

在3月发行的版本中,Microsoft发布了称为SQL Notebook的新功能。 让我们在本文中探讨此功能。

SQL Notebook概述 (SQL Notebook Overview)

Usually, we use Microsoft OneNote to create a notebook and embed documents in it. But with Azure SQL Studio, we can create human-readable documents in SQL Notebook that can include rich format text, code, images. It can also include the query results set in the documents. DBAs can prepare and run the books, troubleshooting guides, baseline documents to store SQL queries, steps and output of these queries.

通常,我们使用Microsoft OneNote创建笔记本并将文档嵌入其中。 但是,使用Azure SQL Studio,我们可以在SQL Notebook中创建易于阅读的文档,其中可以包含丰富格式的文本,代码,图像。 它还可以包括文档中设置的查询结果。 DBA可以准备和运行书籍,故障排除指南,基准文档以存储SQL查询,这些查询的步骤和输出。

This technology is part of open source Jupiter initiative and uses Markdown language to prepare it. As an example, Microsoft Docs uses lightweight mark up language Markdown. It is easy to read language and easily converts into HTML format. Each Markdown document is structurally valid in HTML format.

该技术是开源Jupiter计划的一部分,并使用Markdown语言进行了准备。 例如, Microsoft Docs使用轻量级标记语言Markdown 。 语言易于阅读,可以轻松转换为HTML格式。 每个Markdown文档在结构上均以HTML格式有效。

启动SQL Notebook的不同方法 (Different approaches to launch SQL Notebook)

  1. Connect to a SQL instance and right click on it. In the drop-down menu, click on New Notebook

    连接到SQL实例,然后右键单击它。 在下拉菜单中,单击“ 新建笔记本”

    New Notebook in Azure Data Studio

  2. Go to File -> New Notebook

    转到文件-> 新笔记本

    Launch New Notebook

  3. View -> Command Palette 查看->命令面板

    (Shortcut Key Ctrl + Shift + P)

    (快捷键Ctrl + Shift + P)

    View Command Palette

    In the command palette, type new Notebook and select the highlighted option.

    在命令面板中,键入new Notebook,然后选择突出显示的选项。

    Search in Command Palette

You can use any of the above methods to launch it. Once you launch a Notebook, it opens a default window as per the following image.

您可以使用上述任何一种方法来启动它。 启动笔记本后,它将根据下图打开默认窗口。

Initial screen of SQL Notebook

Azure Data Studio中的默认SQL Notebook布局 (Default SQL Notebook layout in Azure Data Studio)

In the default window, we can see the following areas.

在默认窗口中,我们可以看到以下区域。

layout and description of a notebook
  1. Kernel: It is an important area of a Notebook. We can select the code language and the engine to execute it. For example, the default Kernel is SQL, and we can write t-SQL code in it.

    内核 :这是笔记本的重要区域。 我们可以选择代码语言和引擎来执行它。 例如,默认的Kernel是SQL ,我们可以在其中编写t-SQL代码。

    In the following screenshot, you can see available Kernel in SQL Notebook. If you want to save and run Python code, select kernel Python 3 from the drop-down

    在以下屏幕截图中,您可以在SQL Notebook中看到可用的内核。 如果要保存并运行Python代码,请从下拉列表中选择内核Python 3

    Kernel overview

  2. Attach To: It shows the connection attached to the Notebook. You can add a connection in the drop-down list and select the required details such as name, port number, and default database 附加到:它显示连接到笔记本计算机的连接。 您可以在下拉列表中添加连接,然后选择所需的详细信息,例如名称,端口号和默认数据库
  3. Code: We can click on 代码:我们可以单击+Code to add a t-SQL code in the Notebook +代码在笔记本中添加t-SQL代码
  4. Text: We can add text as well as using文字:我们可以添加文字,也可以使用 +Text + Text
  5. +Code or +代码+Text to add a code or text cell: It is a guide to redirect us for adding code or text in a notebook +文本以添加代码或文本单元格:本指南用于重定向我们以在笔记本中添加代码或文本
  6. Not Trusted: We should review the code and text inside the notebook that it does not contain any malicious code. By default, SQL Notebook is Not Trusted. Once you click on Not Trusted, it turns into a Trusted Notebook in Azure Data Studio

    不信任:我们应该检查笔记本中的代码和文本,其中不包含任何恶意代码。 默认情况下,SQL Notebook 不可信。 单击“ 不受信任”后 ,它将变成Azure Data Studio中的“ 受信任的笔记本”

    Trusted or Not Trusted

    • Note: You cannot change the Trusted notebook to Not Trusted. If you click on Trusted, it shows the following message

      注意:您不能将Trusted Notebook更改为Not Trusted 。 如果单击“受信任”,它将显示以下消息

      Notebook trusted message

  7. Run Cells: SQL Notebook is an integrated notebook that can embed code and text inside it in Azure Data Studio. We can execute code in this as well. Click on 运行单元: SQL Notebook是一个集成的笔记本,可以在其中嵌入代码和文本到Azure Data Studio中。 我们也可以在其中执行代码。 单击Run Cells to execute code inside it 运行单元以在其中执行代码
  8. Clear Results: We might want to execute the code but do not want to save the output inside the Notebook. Click on 清除结果:我们可能想执行代码,但不想将输出保存在Notebook中。 单击Clear Results removes the output 清除结果删除输出

Azure Data Studio中SQL Notebook示例 (Example of SQL Notebook in Azure Data Studio)

Let’s create a notebook in this section. We want to add both SQL query as well as text in a notebook.

让我们在本节中创建一个笔记本。 我们要在笔记本中添加SQL查询和文本。

  • Click on +Text to add text. Once you start writing in the notebook editor, it also gives you a preview as seen in the following screenshot

    单击+文本添加文本。 一旦开始在笔记本编辑器中进行书写,它还会为您提供预览,如以下屏幕截图所示

    Add a text and preview

  • Now, add t-SQL query to get details of SQL Server details such as Edition, version, hostname, Service pack. Click on +Code to add SQL query. You can write a t-SQL on it or paste the query

    现在,添加t-SQL查询以获取SQL Server详细信息的详细信息,例如版本,版本,主机名,Service Pack。 单击+代码以添加SQL查询。 您可以在上面编写t-SQL或粘贴查询

    add t-SQL query in SQL Notebook

  • Once you add a t-SQL query, it automatically assigns the line numbers. We can also see a Run Cell icon in the code block. We can execute a query inside a notebook. Click on either Run Cell icon inside a code block or click on Run Cells.

    添加t-SQL查询后,它将自动分配行号。 我们还可以在代码块中看到“运行单元”图标。 我们可以在笔记本中执行查询。 单击代码块内的“运行单元”图标,或单击“ 运行单元”。

    In the following screenshot, we can see the query output inside SQL Notebook. It is an exciting feature where you can directly execute the code and view the output. If you create notebooks in tools such as Microsoft OneNote, you need to copy the code and paste into SQL editor such as SSMS and execute it. We also need to copy paste the output as well back to Microsoft OneNote to save it.

    在下面的屏幕截图中,我们可以看到SQL Notebook中的查询输出 这是一项令人兴奋的功能,您可以直接执行代码并查看输出。 如果您使用Microsoft OneNote等工具创建笔记本,则需要复制代码并将其粘贴到SQL编辑器(如SSMS)中并执行它。 我们还需要将输出复制粘贴回Microsoft OneNote进行保存。

    Execute query in notebook

    If you do not want to save the output of the query, click on Clear Results. It removes the output as shown in the following image.

    如果您不想保存查询的输出,请单击“ 清除结果”。 删除输出,如下图所示。

    Clear Results to remove output

    Once we click on +Code or +Text, it adds code or text to the end. If we want to add code or text in a specific position(before or after), click on the ellipsis icon, and you get a menu.

    一旦我们单击+ Code+ Text ,它将在末尾添加代码或文本。 如果我们想在特定位置(之前或之后)添加代码或文本,请单击省略号图标,然后会出现一个菜单。

    Add code, text before after a position

    You can select an appropriate option to do the following tasks

    您可以选择适当的选项来执行以下任务

    • Delete the code

      删除代码
    • Insert text or code before this code block

      在此代码块之前插入文本或代码
    • Insert text or code after this code block

      在此代码块之后插入文本或代码


    Let’s add another text block at the end and write text in it.

    让我们在末尾添加另一个文本块并在其中写入文本。

    add text block at the end

    Previously, we paste the code in the SQL Notebook code block. We can quickly write t-SQL as well, and Azure Data Studio Code Snippets helps to write code effectively. We can use existing Code Snippets or write custom Code Snippets as well.

    以前,我们将代码粘贴到SQL Notebook代码块中。 我们也可以快速编写t-SQL,Azure Data Studio 代码段有助于有效地编写代码。 我们可以使用现有的代码段,也可以编写自定义代码段。

    Add a code block and start writing code in it. You get inline suggestion to choose from available Code Snippets.

    添加一个代码块并开始在其中编写代码。 您会获得内联建议,以从可用的代码段中进行选择。

    Code Snippets

    Select the appropriate Code Snippets, and you get brief information of it as well.

    选择适当的代码段,您还将获得有关它的简短信息。

    Azure Data Studio - Code Snippets and SQL Notebook

    Press Enter and click on Run Cells icon inside a code block. If the result does not fit in a block, we can move the slider to see the complete result set.

    按Enter键,然后单击代码块中的“运行单元”图标。 如果结果不适合块,我们可以移动滑块以查看完整的结果集。

    Azure Data Studio - Writing query with code snippets

    • Note: If you have multiple code blocks in SQL Notebook and you click on 注意 :如果SQL Notebook中有多个代码块,然后单击顶部菜单中的Run Cells from the top menu, it executes all the queries and shows outputs. You should click on “运行单元 ”,它将执行所有查询并显示输出。 您应该单击单个代码块上的Run Cell on individual code block to get the output of a particular query only.“运行单元格 ”以仅获取特定查询的输出。

    In the following screenshot, we can see both SQL queries output together.

    在下面的屏幕截图中,我们可以看到两个SQL查询一起输出。

    Azure Data Studio - Execute multiple queries

    You can change the connection to other SQL Servers as well. For example, previously, we executed the queries on SQL2019CTP2.3 instance. Now, we want to run on SQL instance SQL1. Click on Add New Connection.

    您也可以更改与其他SQL Server的连接。 例如,以前,我们在SQL2019CTP2.3实例上执行查询。 现在,我们要在SQL实例SQL1上运行。 单击添加新连接。

    Change or Add new connection

    It opens a Connection Manager in which we can use existing connections or configure a new connection. Fill the details in the connection manager such as connection type, Server, port, Authentication type, and click on Connect.

    它打开一个连接管理器,我们可以在其中使用现有连接或配置新连接。 在连接管理器中填写详细信息,例如连接类型,服务器,端口,身份验证类型,然后单击“ 连接”

    Enter connection details

    In the Attach To section, you can see new SQL Connection, and it executes the code on a new instance as shown in the results as well.

    在“ 附加到”部分中,您可以看到新SQL连接,它也将在新实例上执行代码,如结果所示。

    Execute code in new instance

    You should save SQL Notebook on an appropriate location. If you want to save results as well in Notebook, it might take more space depending upon the result set.

    您应该将SQL Notebook保存在适当的位置。 如果还要在笔记本中保存结果,则可能需要更多空间,具体取决于结果集。

    To save a Notebook, go to File and click on Save As.

    要保存笔记本,请转到文件,然后单击另存为

    Save SQL Notebook

    Give an appropriate name. You can also notice the extension for it Jupyter Notebook (*.ipynb).

    给一个适当的名字。 您还可以注意到Jupyter Notebook的扩展名(* .ipynb)。

    Provide a suitable name and path

    Click on Save. Once you save it, you can see the SQL Notebook name is also modified as per given name.

    点击保存。 保存后,您可以看到SQL Notebook名称也已根据给定名称进行了修改。

    Save notebook

    Azure Data Studio中用于SQL Notebook的Markdown语言 (Markdown language for SQL Notebook in Azure Data Studio)

    We do different formatting in preparing a document using tools such as Microsoft Word, Microsoft PowerPoint. We can do formatting in a notebook using Markdown language. We need to use a few symbols to do formatting in Markdown language. Let’s explore these formatting options in SQL Notebook.

    我们使用Microsoft Word,Microsoft PowerPoint等工具在准备文档时会采用不同的格式。 我们可以使用Markdown语言在笔记本中进行格式化。 我们需要使用一些符号来用Markdown语言进行格式化。 让我们探索一下SQL Notebook中的这些格式选项。

    Headings: In the Microsoft Word document, we use heading such as Heading 1 (H1), Heading 2 (H2), and Heading 3 (H3) etc.

    标题 :在Microsoft Word文档中,我们使用诸如标题1(H1),标题2(H2)和标题3(H3)等标题。

    Headings

    We can create heading for SQL Notebook in Azure Data Studio using the hash mark (#).

    我们可以使用井号(#)在Azure Data Studio中为SQL Notebook创建标题。

    Hash Mark

    Heading

    #

    Heading 1 (H1)

    ##

    Heading 2 (H2)

    ###

    Heading 3 (H3)

    ####

    Heading 4 (H4)

    哈希标记

    标题

    标题1(H1)

    ##

    标题2(H2)

    ###

    标题3(H3)

    ####

    标题4(H4)

    • Note: You should give a space between a hash mark and text.

      注意 :您应在井号和文本之间留一个空格。

      Headings using Markdown language

    Bold Text: We need to enclose word or sentence in two asterisks to make it bold. In the following example, you can see email id is mentioned in two asterisks.

    粗体:我们需要将单词或句子括在两个星号中以使其变为粗体。 在以下示例中,您可以看到在两个星号中提到了电子邮件ID。

    Hi Everyone, This is Rajendra Gupta . You can contact me on
    **rajendra.gupta16@gmail.com**

    大家好,我是Rajendra Gupta。 您可以通过以下方式与我联系
    **rajendra.gupta16@gmail.com**

    Bold text using Markdown language

    Italic Text: We can format word into Italic text by enclosing in a single asterisk.

    斜体文本:我们可以通过将其括在单个星号中来将单词格式化为斜体文本。

    Hi Everyone, This is Rajendra Gupta. You can contact me on
    *rajendra.gupta16@gmail.com*

    大家好,我是Rajendra Gupta。 您可以通过以下方式与我联系
    *rajendra.gupta16@gmail.com*

    Italic text  using Markdown language

    Bold and Italic Text: we can enclose the word in three asterisks to format them in both bold and italic format.

    粗体和斜体文本:我们可以将单词括在三个星号中,以粗体和斜体格式对其进行格式化。

    Hi Everyone, This is Rajendra Gupta. You can contact me on
    ***rajendra.gupta16@gmail.com***

    大家好,我是Rajendra Gupta。 您可以通过以下方式与我联系
    ***rajendra.gupta16@gmail.com***

    Bold and  italic text using Markdown language

    Blockquotes: We can create blockquotes using (greater than) > symbol. It is good to highlight a particular area or text using blockquotes.

    块引用 :我们可以使用(大于) >符号创建块引用。 最好使用块引号突出显示特定区域或文本。

    In the following example, you can see we added a symbol > to make it as a blockquote.

    在以下示例中,您可以看到我们添加了一个符号>,使其成为blockquote。

    >Hi Everyone, This is Rajendra Gupta. You can contact me on
    ***rajendra.gupta16@gmail.com***

    大家好,我是Rajendra Gupta。 您可以通过以下方式与我联系
    ***rajendra.gupta16@gmail.com***

    Blockquotes using Markdown language

    Links: We might want to add a reference link in the SQL Notebook as well. We can add links in Inline link format.

    链接 :我们可能还想在SQL Notebook中添加参考链接。 我们可以以内联链接格式添加链接。

    [link text](URL)

    [链接文字](URL)

    In the following example, it creates a link for SQLShack.

    在下面的示例中,它为SQLShack创建一个链接。

    >Hi Everyone, This is Rajendra Gupta. You can contact me on
    ***rajendra.gupta16@gmail.com***.
    Find my articles on [SQLShack](https://www.sqlshack.com/author/rajendra-gupta/)

    大家好,我是Rajendra Gupta。 您可以通过以下方式与我联系
    ***rajendra.gupta16@gmail.com***
    在[ SQLShack ]( https://www.sqlshack.com/author/rajendra-gupta/ ) 上找到我的文章

    Links using Markdown language

    Unordered List: Use a dash (-) to list items in an unordered way.

    无序列表:使用破折号(-)以无序方式列出项目。

    – Hi Everyone, This is Rajendra Gupta. You can contact me on
    ***rajendra.gupta16@gmail.com***.
    – Find my articles on [SQLShack](https://www.sqlshack.com/author/rajendra-gupta/)

    –大家好,我是Rajendra Gupta。 您可以通过以下方式与我联系
    ***rajendra.gupta16@gmail.com***
    –在[ SQLShack ]( https://www.sqlshack.com/author/rajendra-gupta/ ) 上找到我的文章

    Unordered list

    We can also create a Nested list in Markdown language with a tab and dash. In the following example, you can see Nested list.

    我们还可以用Markdown语言创建带有标签和破折号的嵌套列表。 在以下示例中,您可以看到嵌套列表。

    – Hi Everyone, This is Rajendra Gupta. You can contact me on
    ***rajendra.gupta16@gmail.com***.
    – Find my articles on [SQLShack](https://www.sqlshack.com/author/rajendra-gupta/)

    –大家好,我是Rajendra Gupta。 您可以通过以下方式与我联系
    ***rajendra.gupta16@gmail.com***
    –在[ SQLShack ]( https://www.sqlshack.com/author/rajendra-gupta/ ) 上找到我的文章

    Nested list using Markdown language

    Ordered or Number list

    订购或编号清单

    We can write steps sequence in a document using an ordered list. To create an ordered list, write a number in front of it. It automatically assigns an incremental number for the list items.

    我们可以使用有序列表在文档中编写步骤序列。 要创建有序列表,请在其前面写一个数字。 它会自动为列表项分配一个增量编号。

    1. Hi Everyone, This is Rajendra Gupta. You can contact me on
    ***rajendra.gupta16@gmail.com***.
    1. Find my articles on [SQLShack](https://www.sqlshack.com/author/rajendra-gupta/)

    1.大家好,我是Rajendra Gupta。 您可以通过以下方式与我联系
    ***rajendra.gupta16@gmail.com***
    1.在[ SQLShack ]( https://www.sqlshack.com/author/rajendra-gupta/ ) 上找到我的文章

    Ordered list using Markdown language

    Tables

    桌子

    We can also create tables using the Markdown language. It is not straightforward to create a table SQL Notebook.

    我们还可以使用Markdown语言创建表。 创建表SQL Notebook并非易事。

    • We need to use at least three dashes to separate each header cell

      我们需要至少使用三个破折号来分隔每个标题单元格
    • We use outer pipe (|) to separate each column

      我们使用外管(|)分隔各列
    • We can use optional colons “:” for column alignment

      我们可以使用冒号“:”进行列对齐


    In the following example, we created a table with three columns and two

    在下面的示例中,我们创建了一个包含三列和两列的表

| EmpID         | EmpName           | Country  |
| ------------- |:-------------:| -----:|
|1              | Rajendra-aligned  | India |
|2              | Raj               | India |

Tables  using Markdown language

Images

图片

We can add images using Markdown language in the following format.

我们可以使用Markdown语言以以下格式添加图像。

![alt text](Image Link) “Image Title”

![替代文字](图片链接)“图片标题”

In the following example, we can see the ApexSQL Logo in the notebook.

在下面的示例中,我们可以在笔记本中看到ApexSQL徽标。

![ApexSQL Logo](https://www.apexsql.com/images/ApexSQL_Logo.png “ApexSQL Logo”)

![ ApexSQL徽标 ]( https://www.apexsql.com/images/ApexSQL_Logo.png “ ApexSQL徽标” )

Images using Markdown language

We can also specify an image in the following reference style.

我们还可以使用以下参考样式指定图像。

![alt text][logo]
[logo]: https://www.apexsql.com/images/ApexSQL_Logo.png “ApexSQL Logo”

![ 替代文字 ] [徽标]
[徽标]: https ://www.apexsql.com/images/ApexSQL_Logo.png“ ApexSQL徽标”

Images  using Markdown language

Videos

影片

Suppose we want to create a learning guide using SQL Notebook. We might save videos link for a reference purpose. We cannot directly add videos here but can add a reference hyperlink with a preview or image of the video. You can click on this image to redirect and play the video.

假设我们要使用SQL Notebook创建学习指南。 我们可能会保存视频链接以供参考。 我们无法在此处直接添加视频,但是可以添加带有视频预览或图像的参考超链接。 您可以单击此图像来重定向和播放视频。

In the following example, I added a video link and used ApexSQL logo as a video. You can click on this image and it opens a new browser window to play the video.

在以下示例中,我添加了视频链接,并使用ApexSQL徽标作为视频。 您可以单击此图像,它将打开一个新的浏览器窗口以播放视频。

<a href=”https://www.microsoft.com/en-us/videoplayer/embed/RE2EgJl” target=”_blank”><img src=”https://www.apexsql.com/images/ApexSQL_Logo.png” alt=”IMAGE ALT TEXT HERE” width=”150″ height=”40″ border=”10″ /></a>

<a href=” https://www.microsoft.com/zh-cn/videoplayer/embed/RE2EgJl” target="”_blank”> <img src =” https://www.apexsql.com/images/ApexSQL_Logo。 png ” alt =”此处输入图片替代文字” width =“ 150” height =” 40” border =“ 10” /> </a>

Videos using Markdown language

结论 (Conclusion)

In this article, we explored useful feature SQL Notebook in Azure Data Studio. It can help to prepare technical documentation, SOPs, troubleshooting guides, release notes, etc. I will explore more on this feature in future articles. If you had comments or questions, feel free to leave them in the comments below.

在本文中,我们探索了Azure Data Studio中有用的功能SQL Notebook。 它可以帮助准备技术文档,SOP,故障排除指南,发行说明等。我将在以后的文章中进一步探讨此功能。 如果您有任何意见或问题,请随时将其留在下面的评论中。

翻译自: https://www.sqlshack.com/sql-notebooks-introduction-and-overview/

sql概述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值