Azure Data Studio (ADS) is a lightweight IDE built on Visual Studio Code. I’ve written a few articles on how the tool works, and I’ve got a few more coming. I covered a basic orientation and a more in depth one on some of the code writing features. In this one, I wanted to cover a very interesting feature that was added to the March 2019 release of ADS. You can download the tool and read those articles to learn about how to use this in writing code. I’ve gotten more comfortable with the tool, and while I still like SSMS, there are some features in ADS that I prefer.
What is a Notebook?
I’ve been using notebooks for a few years in different parts of my work. I’ve learned from Python and Jupyter Notebooks are a way of capturing a number of different code items with text and sharing the information with others. I’ve actually been doing a little work with Azure Notebooks and have written a few blogs. Not all of my notebooks are public, but I do like them in terms of a way to structure the flow of some concept. I’ve used them to experiment and document how things work, allowing me to easily follow along again.
Notebooks are an open data format, essentially a an application that you use to write some document, but they contain live code elements that allow you to embed programs, images, results, and more inside of them. It’s really a fantastic tool for teaching or sharing information between people, which is something I’ve struggled to do with other DBAs and developers. A notebook makes it easy to link lots of docs and code together.
When I first heard that we were getting T-SQL notebooks, I was excited. This is a technology that ought to have been embedded in Word, Excel, and other places in the past, but it hasn’t been. The past is the past, and we can now move forward.
Getting Started with Notebooks
You need a version of Azure Data Studio that is 1.5.1 or later. This is the March 2019 release and contains notebooks with both T-SQL and PGSQL capabilities. I’ll only cover T-SQL, but I assume things work similarly with PostgreSQL.
We can create a notebook just like we create any other object. We use File | New and select New Notebook. This is a first class object like a file or other item in ADS.
When the notebook opens, there’s nothing to see, but a little guidance on how to begin. ADS lets you know that you can add code or text to a cell, whatever that is. A cell is essentially a section of your notebook document. You can interleave code and text, but they are separate elements that format in whatever order you’ve placed them. You can click on either of the words, but in the menu bar at the top there are also buttons for adding text or code cells.
Let’s start with code, because many of us write code. I’ll click the “+ Code” link in the notebook. This will give me the view below, in which I can now write T-SQL code.
This is a code block like in any other query, but it’s self contained. It’s as if I have a tab embedded in my notebook that just runs the code inside this rectangular blog. Notice there is a “Run” button with a triangle on the left. I have a line number, which grows as I add lines. I also have an ellipsis (three dots) on the right. There are other items in here, but let’s write some code. I’ll add a couple simple lines of code so that you can see how this works.
I have multiple code lines in here, two queries to run. If I click the black button with the triangle (Run), nothing happens. Why? This is because the notebook isn’t connected to any server. I can’t run code without a SQL Server instance, so I’ll need to connect to something. If I click the drop down that says “Select connection”, I get a choice. I haven’t added anything to this notebook, so I just have “Add new connection”.
If I select that, the ADS connection dialog opens. I can put in my information and make a connection. This is a fairly standard connection dialog.
Once that’s done, I can now click the Run button in my notebook and get results. The format is fairly standard ADS, but embedded in the cell itself, which you can see as grown a bit.
This article covers SQL Server 2008 Service Broker, an asynchronous messaging framework that is directly integrated within the relational engine of SQL Server. The series will provides you with the basics about implementing Service Broker applications and how you can transparently scale them out to support any required workload.