TSQL Tuesday #137 Using Notebooks Every Day

This post is over 24 months old, that is an lifetime in tech! Please be mindful of that when reading this post as it could be outdated. I try to keep on top of changes where possible. I try to keep things up to date, but if you think something needs updating, please let me know in the comments.

It’s #TSQL2sday!!

T-SQL Tuesday is the brainchild of Adam Machanic (Blog | Twitter). December 2009 was the first T-SQL Tuesday invitation that went out by Adam. It is a monthly blog party on the second Tuesday of each month. Currently, Steve Jones (Blog | Twitter) organises the event and maintains a website with all previous posts which you can find here. Everyone is welcome to participate in this monthly blog post.




The Ask

This month’s T-SQL Tuesday is hosted by Steve Jones (Blog | Twitter). Steve invites us to write about how we have used, or would like to use, a Jupyter notebook..

How do I use Notebooks?

I have had a play with them on and off but not really used them in anger, I have also not observed them in use anywhere I have been (so far). The invite has led me to do some research on Notebooks, it’s been quite interesting to learn a bit more and consider the possibilities. A big shout out to Rob Sewell, his blog has been a brilliant resource and some of the ideas he has presented have been really interesting, I highly recommend you checking it out.

What is a Notebook

Jupyter Notebook is an open-source web application, allowing you to create documents containing code, images, text and interestingly, execution results. You can author Notebooks using Azure Data Studio which is great, because it means I get to play with them directly on my Mac :)

Using Notebooks

Documenting

The text cell provides rich text and markdown interfaces. You can toggle them using the switches on the far right. The first icon provides a rich text interface, the second provides rich text plus preview, the third icon provides a markdown interface.

the upper right section of a notebook cell, there is a preview icon underlined, a split view and a markdown view

I like using markdown - my site is powered by Hugo which also uses markdown so it is possible for me to copy content from my site into a Notebook if I were to create a supporting Notebook to a blog post lets say….or just to be able to reuse content easily. I have been using Azure DevOps Wikis quite a bit of late and that also uses markdown so it’s a useful language to become familiar with. There is a great guide for markdown here .

Adding images

Most markdown seems to be supported, though I haven’t had any luck using local image references. You can reference images like so;

![local](./image.webp)
![external](http://tsqltuesday.com/wp-content/uploads/2017/02/tsqltuesday.jpg)

The first command references a local image and won’t work, whereas the second command references a remote one. However, it is possible to paste images straight into a text cell using rich text! So from my Mac I can hit ⌘ + ctrl + shift + 3 (contorting my fingers!), draw a box around a portion of my screen and that will be clipped straight to clipboard which I can then paste straight into the Notebook!

Adding code

Focusing on SQL, you can create a code cell and write code that can be executed directly within the Notebook. If you create multiple cells these can be run one at a time or all at once;

image of the notebook interface, each cell has a play button which will run the current cell, at the top of the notebook is a 'run all' button which will run each cell in sequence

What is really interesting with this, is that the execution results are stored with the notebook! This provides some interesting opportunities.

How I might use them in the future

Operations runbook

The ability to enrich code with images and annotations provides some interesting opportunities to build clear and concise operational documentation. This could be a set of steps in order to run through an entire process, or to take remedial steps following a load failure.

Troubleshooting

The ability to store results provides some interesting troubleshooting opportunities. For instance, a Notebook could be created to capture metrics in the event of an issue in order to assess them the following day, it also offers the ability to send remote users / clients a suite of queries to assist with troubleshooting, those queries could be run and then returned to you without being on site. Pretty cool!

Automation

Rob has done some cool stuff with automating Notebooks that I need to sit down and have a play with, I suggest you check it out too! I will be exploring this more in the coming months and appreciate Steve picking this as it’s been a worthwhile exploration.

Sharing

I have edited this post to add…in wrapping this up I decided to push the Notebook I used to create some screenshots, to Github so I could share it in the post. What I was surprised to see was that Github does a very neat job of displaying the notebook to you, check it out !

Tags :

#mtfbwy



Recent Posts

How to Search for a Lost File in the Git Log

How to Search for a Lost File in the Git Log

  • 2024-04-27
  • 4 minutes to read

I have lost a file in my Git repository. How can I find it by searching the git log?

Read More
No Such Shell Function 'Zle Line Init' in Zsh

No Such Shell Function 'Zle Line Init' in Zsh

  • 2024-04-25
  • 3 minutes to read

Troubleshooting the error message "no such shell function 'zle line init'" in zsh when using OhMyPosh.

Read More
Getting Started With Python in Vscode

Getting Started With Python in Vscode

  • 2024-04-05
  • 2 minutes to read

This post will help you get started with Python in Vscode and identify some of the useful extensions to install.

Read More