ADS: Notebook Text Formatting

Azure Data Studio has a great feature in the form of Notebooks.  A notebook is a document that allows for executable code such as TSQL or Python as well as notes for documentation.  Notebooks can be utilized to help organize things such as DR runbooks and troubleshooting documents.  What I like best about notebooks is that everything needed can be located in a single file, including data.

When working in a Notebook you have two types of cells, text and code.  The focus of this post is how to format the text cell.  Of course text goes into this cell so that part is easy and of course the text can say anything you would like to say.  When we work with text in Word, there is a format tool bar that we can use to make it look like we want it.  The text cells do not have this toolbar.

You might be asking, without the format toolbar, does that mean we can’t format the text?  That answer is no….we can still format the text, we just need to do it slightly different.  Rather than use a toolbar, we need to use characters.

While not all formatting options are available in Notebooks, there are a few commonly used options that are.  These are below as well as a few others we won’t cover in this post.

        • Font Size
        • Font Weight
        • Bullet lists
        • Italics

Here is an example of what your text might look like with formatting.  Notice that there are different size fonts, bold fonts, email address, URL and a small section highlight(blue vertical bar).  We will go over each of these in this post.

First of all, in order to get to the location that allows you to format the text, you simply need to find the text you want to format and double click on it.  When you do, the box to format the data will appear just above it.  Similar to below.

The chart below has an example of each of the font options. The sample code is in the parenthesis.

 

Font Changes in a Notebook

Formatting Applied and Sample code Example
No Formatting
One #

(# Font Changes)

Two #

(## Font Changes)

Three #

(### Font Changes)

Four #, adds bold

(#### Font Changes)

Five #, adds bold

(##### Font Changes)

Six # – Makes font tiny and bold

(###### Font Changes)

Seven # – no impact at all, prints the # signs

(####### Font Changes)

Italics

The above chart shows how to change the size and weight of the text.  Well, what if I want the text to be italics.  To do this we will use the *, well actually a pair of them. One will be placed at the start of the text you want to be italics and the other will be placed at the end.

Like this:   *Font Changes*

This is what it will look like in a Notebook

If you want a larger font you can combine characters.

Using both the # and *, we can get a larger font as well as italics.

This is what it would look like:  # *Font Changes*

The image above shows a much larger font and italics.

URL

If you want to include a URL to a web site you can easily do this with out the use of any special characters, such as a # or *.  When you do, the text to the URL appear just as you type it.  For example, if I want to include a link to my blog I could type, www.davebland.com.  When I do, that is exactly how it will appear in the text, www.davebland.com.

However, what if I want different text to appear, let’s say I want “Dave Bland’s blog” to appear in the text rather than www.davebland.com.  This is also pretty easy.  You will need to utilize the square brackets, [] and a pair of parenthesis, ().

The square brackets will hold the text I want to appear, while the URL will be placed between the ().

Like this:

[Dave Bland’s Blog](https://www.davebland.com)
Here is an example of both.

 

Bold

We already talked about how you can use the # to get a bold font.  But what if I want a word in the middle of the text to be bold and nothing around it.  This is where the * comes in.  We just put two * before and two after the text we want bold.

Like this:

# I what these words to be bold: **Font Changes**
This is what it will look like.  Notice the # at the start, remember this makes the font larger.

 

Block of Text

Azure Data Studio also offers the ability to block off sections of text, similar to the text in the green box  below.  Notice the blue vertical bar and the tinted background.

This is done by placing a > at the start of the line.

This is what it will look like:

You can add more > at the front if you like, this will create blocks in a block.

This is what it will look like:

>>### “Those responsible for sacking the people who have just been sacked, have been sacked.” – What movie is this from?

 

And this is the result:

Bullet Lists

The final format item I would like to cover it a bullet list.  Like all the other format options, this is completed by the use of a special character.  In this case it is the plus sign, +.

This is what it will look like:

+ First Bullet
+ Second Bullet
This is the result:

Put it all together

If you use a number of these in one text box, this is what it might look like.

And this is the result:

There you have it….formatting text in Azure Data Studio notebook without the use of a format toolbar.

Thanks for visiting my blog!!!

 

 

 

 

Auto Delete Jobs????

Have you ever looked at something in SQL Server and wonder why it is there?  That is what I think when I see this option in the SQL Server Agent job properties.  I can not come up with any good reason of why you would want a job to delete itself upon completion.  I even did a Google search and really didn’t find a good reason.  However, if you know of a great reason of why you would want to enable this, I would love to hear about it.

If you are not familiar with this option, you can find it under the Notifications tab of the job properties.

Just like all the notifications, you have several options.

      1. When the job secceeds
      2. When the job fails
      3. When the job compeletes

When the job deletes, it will also take a job history with it.  Basically there will be no evidence that the job ever existed.  This is pretty straight forward, so you might be wondering why bring it up.  Well, I see this setting as a potential danger, especially if you have a disgruntled DBA.  While being a DBA is a great job, there are, from time to time things that can have a negative impact on how we feel about our job.  Luckily the SQL Server community is filled with really great people.

We have a job that checks all of our jobs looking for any jobs that has this set.  You can use the query below to get the necessary information. There is a column, delete_level in sysjobs that will allow us to get the information needed.

SELECT    name
  , delete_level
  , CASE delete_level
    WHEN 0 THEN ‘Not Set’
    WHEN 1 THEN ‘Delete on Success’
    WHEN 2 THEN ‘Delete on Failure’
    WHEN 3 THEN ‘Delete on Completion’
    END AS ‘Delete Level Setting’
FROM sysjobs

So why do I think this is potentially dangerous?  Image the disruptive code that could be written and then imagine that same code in a job that is scheduled to execute 6 months later.  Now go one step further, all evidence of that job running is now gone.  I really don’t want to give too much information, but I can think of several things that could be done that could cost the company a ton of money.  This is why we check for this.

I also include this check on my server assessment scripts.

As I said earlier, if anyone can give me a good reason to have this set, I am willing to listen and will update this post accordingly.  Giving proper credit of course.

My suggestion is to look for this!

Thanks for visiting my blog!!!!

Azure Data Studio – Schema Compare Extension

From time to time we are asked to help identify the differences between two databases.  For example, the differences between a database in QA and the same database in production.  Over the years I have become accustomed to using a very nice tool by Red-Gate, SQL Compare.  With the release of Azure Data Studio and the SQL Server Schema Compare extension, I now have another option.  As with many of the extensions, this one is also in preview.

In order to install the extension, after opening the extensions in Azure Data Studio, you will want search for Schema Compare, similar to the image below.  Notice the white star in the upper left corner, this means that this extension is recommended by Azure Data Studio.

Installation is very easy, once you have found the Schema Compare extension, click the Install button.  This is a pretty quick install and does not require a restart of Azure Data Studio.

Once installed you can launch the Schema Compare extension in one of two ways.  The first way is to right click on one of the databases you wish to compare and go to Schema Compare in the context menu.

The second method is to use the Command Palette.  You can reach this from the View menu.

The difference between the two is that if you use the Command Palette, both the source and target locations will be empty.  If you right click on a database to compare, that database will be the source and the target will be empty.

Using the Command Palette – notice both the source and destination are blank.

Right clicking on a database – the source is already populated with the database you right clicked on.

Setting up the Source and Destination

When setting up the source and destination, you will have a choice to make.  Will you compare a database or will you use a DACPAC to complete the compare?  You don’t have to just compare two databases, you can compare a database and a DACPAC if you have a need to do so. When you click the ellipsis to the right of either the source or destination, you will be taken to the location that will let you set up the comparison.

What I like is that I don’t have to do a database to database compare or a DACPAC to DACPAC compare.  Schema Compare allows for a database to DACPAC compare as well.  Once set up your screen will something like what you see below.

Since I am comparing two DACPACs, there is a path, however if either the source or target is a database, it will look similar to below.  The format is ServerName.databasename.  In this case since I am using a named instance it is slightly different, ServerName\InstanceName.DatabaseName.

Menu Options

Once you have set up the source and target, the menu bar will appear across the top.

Let’s take a moment to go over each of these.

Compare and Stop – these are pretty simple and are used to start the compare or stop it.

Generate Script – Once the compare is done, we can use this to generate the script we can use to make the changes.  Notice in the image above this is not active. It will become active after you have completed the compare AND you are comparing two databases.  You will not be able to use this option when comparing two DACPACs.

Apply – Will apply the discovered changes to the target

Options – There are a number of options that include rules to follow, like “Block on Possible Data Loss” and what to include in the compare.  “Ignore Permissions” is an example.

Switch Direction – This will take the source and make it the target…and of course take the target and make it the source.  When you click this, the arrow between the two will stay pointing to the right, the items to compare will move.

Open .scmp\Save .scmp – Schema Compare allows you to save the configuration to run the compare again at a later date if you like.  If you save it after the compare is completed, this will NOT save the results of that compare.  These files are XML based and will look similar to below.  The format is pretty simple, the XML will contain the version, source, target and the current state of all the options.

 

Changing Target or Source

Once the target and source are set up, you can easily change one or both of them.  Simply click the ellipsis again, make the changes you want and click “OK”.

When you do make a change and click “OK” the following will appear in the lower right corner of Azure Data Studio.   It is just asking if you want to complete the compare now.  If you click no, you will still be able to complete the compare by clicking “Compare” when you are ready.

Generate Script

This does exactly as you would expect it to. It generates the script.  Once the compare is complete, as in the image below, the Generate Script option becomes active.  Just a reminder, if both the source and the target are DACPACs, generating the script is not an option.

Prior to generating the script, you will want to review what was found, specifically the Include and Action columns to make sure those are indeed the changes you would like to make.  If there is a difference you do not want to be part of the script make sure to clear the check box in the include column.  Once Azure Data Studio is completed with the generation of the script a new table will open up.  This tab will not be connected to a data source.  If you want to run it, you will need to connect to the desired data source.

Notice in the bottom left corner of the above image you see “Problems” with the number 7 to the right of it.  Initially you might think that Azure Data Studio created bad code, that is not the case.  When you click on “Problems” you will see a list of the problems as well as the line number and the location of the first character of the problem.  If you click on one of the problems, you will be taken to that location.

You still might be thinking ADS created bad code.  Now I will show that the code is just fine.  If you look at the code and scroll down just a bit you will see this.

“Detect SQLCMD mode and disable script execution if SQLCMD mode is 
not supported.

 

The code that is generated requires that SQLCMD be active. Once SQLCMD is active, the problems disappear.

Now you are able to run the script when you are ready.  Of course, the script can be saved as a .sql file if you want to run it later.

I think this is a very useful warning that can be found near the top of the generated script.

“This code was generated by a tool.
Changes to this file may cause incorrect behavior and will be lost if
the code is regenerated.”
Just something to think about before making any changes.

Options

The final item I would like to cover is the Options button.  Of course this is exactly what you might think it is, a location to set options.

When you do click this, a panel will open up on the right side of Azure Data Studio.  At the top of this panel you will see two options.

The first options is “General Options”.  This is where you can identify what you actually want to capture in the compare. While the second option will identify the object types you want to be looked at, for example tables, views or stored procedures.

Under the General Options there is one in particular I would like to point out, Verify Deployment. Having this checked, the deployment will not be allowed to proceed if the validation detects a problem.  The image below is the actual description you will see.

As time goes on we will use this extension more and more, we will then have a better understanding of some of the additional options we might want to include.  You should really check this extension out!

Thanks for visiting my blog!!

ADS – Did I Save My Changes?

After working on a query for a long time, we want to make sure that we save the changes we have made.  I have lost hours of work over the years because I didn’t save the changes.  Azure Data Studio has a few features that can help prevent this from happening.

The first feature is that ADS can “save” your changes if ADS is restarted.  This can be turned off in Preferences.  I completed a blog post on this feature.  Here is the link.  This feature allows Azure Data Studio to remember what changes you made and will open the file when you restart ADS.

In SQL Server Management Studio an asterisk is placed on the tab the code is on.  Once you save the file, the asterisk will disappear.

Azure Data Studio is similar but instead of an asterisk, ADS uses a dot.

Once the file has been saved, the dot changes to an X.

What is interesting is that if the file has not been saved when ADS is closed, the unsaved state will be retained.  The next time you open ADS, the file will be opened, the changes will still be there and the file will be marked as not saved.

This is a short and simple blog post.  Thanks for visiting my blog!!!

ADS – Outdated Extensions

As you add more and more extensions to Azure Data Studio,  keeping them up to date could present a challenge.  Of course we will want to install all the extensions that we think might be helpful to us.  Luckily Azure Data Studio has a nice way to let us know if there is an extension that is out of date.

If you look at the extensions in the left vertical bar you will see a number over the extensions, the blue circle. That number represents the number of extensions that have updates available. In the image above, you can see that there is one extension that is out of date.

Now we need to find that particular extension.  You can do this by scrolling through you active extensions and look for the green box as in the above image.  This will take you to the proper location for the update.  In the case above, I needed to update the Redgate SQL Search extension.

This is an update to the VISX file.  Once you download it, you will then need to click on the “Install extension VISX package” item under the File menu.  Prior to installing the new version, I would suggest that you review exactly what the new version brings.

As with the initial install of the extension, it is possible that you may need to restart Azure Data Studio to complete the installation.  In this case, there was a nice reminder to do so.

Thanks for visiting my blog!!!

ADS – Query History Extension

I just downloaded the latest release of Azure Data Studio.  A new extension came with it that I really like, Query History.  According to the documentation, the Query History extension does this: “Adds a Query History panel for viewing and running past executed queries”.

This installation of this extension is pretty simple and does not require a restart of Azure Data Studio.  However, if you disable or uninstall the extension, you will need to restart ADS.

If you look at the View menu, you will notice that there is not a menu item for “Query History”.

This will change once the extension is installed.  You will find the Query History item just under Output.

Once you install the extension, you will now begin to see query history.  If you run a query, you will see the history as seen below.  If you to not see this at the bottom of the screen, go to the menu item mentioned above.

When you run a query, it takes a very short period of time for it to appear in the history.  In the above image,  I ran three queries, two of which were the same query.  This window is not part of the query window.  Since it is a separate window, it will collect queries from all tabs that are open.  Each row in the history will return three things, the query, the server and database uses as well as the times stamp of when the query was ran.  The server can be seen in the green box below.  Sometimes a forth item is included in the list of items returned, the icon that is at the far left of each row.

Now that we have history, let’s take a moment to see what we can do.  First of all, if you float your cursor over one of the queries, you will see a pop up.  This pop up will display the query.

You will see a lot more options if you right click on one of the queries.

All the options are pretty straight forward and really don’t need a great deal of explanation.  The bottom option, Pause Query History Capture I can see being useful if you are running query that you don’t want to be part of the history or just running too many queries at the moment.

Since these options are pretty straight forward, let’s take a look at a few questions.

What happens to the history when Azure Data Studio is closed?

The history is no longer available

What if I execute a batch, will each query in the batch be a separate line?

All the queries for the batch will be on the same line. The query in the green box is actually two select statements.

To the left of the query, I see a green check mark.  What are other icons I might see? 

There is currently only one other icon you might see. The red X when there is an error.

When there is a error, you will see a small number next to the “Problem” tab.  When you clock to this tab, you can now see details on what the error was.

What’s the difference between “Run Query” and “Open Query”?

Open query will do just that. Open the query so you can review the TSQL.  Run query will simply run the query and you will see any results if there are any.

Over all I really like this extension and can really see the practical use of it.  Just remember, this extension does not stored the queries beyond the Azure Data Studio session.

Thanks for visiting my blog!!!

 

 

 

 

Azure Data Studio – Process Explorer

Looking at processes in Windows Task Manager is something that most DBAs have done many times.  The need to do this hasn’t changed, however what has changed is how we can get information on the processes.

Prior to Azure Data Studio we would go to Task Manager in Windows.  Task Manager will look something like this.  You can see the name of the process, user name, PID number as well as CPU and memory utilization.

Azure Data Studio offers the ability to view these same processes, however the processes returned focus on Azure Data Studio related processes.

To open Process Explorer, go to the Help menu item and it is in that menu.  Just as in the image below.

Once open you will see familiar columns.  These columns include, CPU%, Memory(MB), pid and Name.  These are all Azure Data Studio related processes.

When you right click on one of the processes, you will see a somewhat familiar pop up menu.  The menu item will allow us to terminate the process, just as we have done many times in Task Manager.

This pop up menu is significantly smaller.  The task manager pop up has a ton more options including change priority and affinity. Below is what you will see in the pop up menu in Task Manager.

Looking at the image below, the left side is Azure Data Studio and the right is Windows Task Manager.  The important thing to note here is that in order to map the process to a process in Task Manager, the match will happen on the Pid column, as seen below.

Notice that the pids all point to the azuredatestudio.exe processes.  Azure Data Studio provides just a bit more information than Task Manager.  Please be careful changing the state of a service.  In other words, be careful stopping a process unless it is a last restore approach to fixing an issue.

In Task Manager the sort order for a column can easily be change.  You will need to put in just a bit of effort into determining what the proper sort order is.  When looking at the data in Process Explorer, the data cannot be sorted in any way.  It looks like it is sorted by CPU in descending order.

This is a pretty short blog, but I think it is a good idea to know thqt Process Explorer exists.  I really like that I can stay in the same tool and review related processes.

Thanks for visiting my blog!!!

 

ADS: Why doesn’t the app ask to save anything when I close it?

Azure Data Studio has many great features and even more if you add all the extensions that are available.  Many extensions are very useful now, even though they are still in preview.  These features are naturally compared to SQL Server Management Studio.  One feature I like that sort of exists I SSMS is the auto save feature.  This feature will automatically save your files when you close Azure Data Studio and will be there the next time you use ADS.  SSMS has the auto recovery option, but is works a bit differently so it isn’t quite the same. ADS has a setting named “Files: Hot Exit”.

If you open Settings and then do a search on “save”, you will see a few settings returned.  The one we are looking for is under “Text Editor” then “Files”.  When you click files you will see the setting at the bottom.

When you click the drop down box you will see three options, Off, onExit and onExitandWindowClose.  What I like about it is that as you float your cursor over each option, a description appears below it. As you can see below, onExit is the default option.

According to the documentation from Microsoft, these are the descriptions of the three options, these are directly from Microsoft here.

      • "off": Disable hot exit.
      • "onExit": Hot exit will be triggered when the application is closed, that is when the last window is closed on Windows/Linux or when the workbench.action.quit command is triggered (from the Command Palette, keyboard shortcut or menu). All windows with backups will be restored upon next launch.
      • "onExitAndWindowClose": Hot exit will be triggered when the application is closed, that is when the last window is closed on Windows/Linux or when the workbench.action.quit command is triggered (from the Command Palette, keyboard shortcut or menu), and also for any window with a folder opened regardless of whether it is the last window. All windows without folders opened will be restored upon next launch. To restore folder windows as they were before shutdown, set window.restoreWindows to all.

While this feature may give the perception that the changes were saved, in reality the file on disk has not changed at all.  The image below shows a change to the word “Total(s)”.  The top Totals is the word in Azure Data Studio after a change and after a close of the ADS.  The bottom one is from the file that was opened in SQL Server Management Studio, notice there is an “s”.  This shows that despite ADS persisting the change when ADS is restarted, but actual file was not changed.

I really like this option.  Not only will it “save” the files, but it will also save any text you have selected.  If you have a block a text selected and Azure Data Studio is closed, your text will also be selected when you restart Azure Data Studio.

This will not only save your files, but it will also save a number of other items that you may have open.

If you have the Settings open when ADS is closed, it will also be open when reopen ADS.  Although you may not be in the same place in Settings when you return.  If you have the connections window open, this will also be open when reopening ADS.  Like Settings, you may not be in the same place in Connections when I reopens.

Although there might be some Settings you might want to change, for me personally I don’t think this one should be on the list of things to change.

Thanks for visiting my blog!!!

 

Azure Data Studio – Delete Database Extension

While we don’t delete production databases very often, that is not the case with development or even on the local instance of SQL Server on our laptop. We may delete databases from these lower environments quite often. Out of the box, Azure Data Studio does not provide the ability to right click on a database and delete it.  SQL Server Management Studio has had this functionality all along.  Like most other extensions, this is still in preview.

If you look at the image below, you can easily see that there is NOT a delete option.

While we are able to use the DROP DATABASE statement, sometimes is it nice to just right click on a database and delete it. There is now an extension available named Delete Database.  There is the link to the GitHub for this extension.  Once installed you will now see the Delete option.

When you first go to the extension options in Azure Data Studio you want to look for this extension.

When you click on the extension, you will see what is below.   There really isn’t much information here, although to be fair, this is a pretty simple extension.  It does one thing, adds an option to the context menu when you right click on a database.

This extension is installed by using the “Install Extension with VISX package” option under the File menu.

Once installed you can now right click on the database and delete it.  However, something to keep in mind, you will not see the usual popup you would see in SSMS.  You will see this in the lower right hand corner of Azure Data Studio.

When you click yes, the database will be deleted and the list of databases under the “Databases” item in the connection will automatically update.  That is not the case if you use the code below.

DROP DATABASE [test4]

If the DROP DATABASE statement is used, you will need to manually refresh the list of databases.  In the image below, the DROP DATABASE statement was executed and I then right clicked on Databases, and the database was still in the list.  If I right clicked on the server, in this case LocalHost and then refresh, the database list was refresh as expected.

If this is the first time visiting this page, you will see the Install button, click that button and you will be taken to the GitHub for the extension.  The VSDI can be downloaded there. Remember to place it in a location that other processes will not delete it.

After the installation is completed, you will not need to restart Azure Data Studio to utilized the Delete option on the context menu.  However, if you disable the extension, you WILL need to restart ADS.

As always, use caution when deleting databases.  Deleting the wrong database can be a major outage event.  So use caution when attempting to delete a database.

Thanks for visiting my blog!!!

ADS – AutoClose Database Setting

Recently when working with Azure Data Studio, I noticed something I hadn’t seen before. I noticed to the right of the database name the words “Auto Closed”, as in the image below.

Let’s take a quick second to go over exactly what Auto Close is and what it means.  Auto Close is a database level setting that can be set to either On or Off.  When this is set to On, SQL Server behaves slightly different.  SQL Server will open and close the database for each connection.  While this creates additional, usually unneeded overhead, this isn’t the only concern.  When Auto Close is set to ON, it will free up all the resources it is currently consuming, including the plans in the plan cache.

To turn this on or off, you will need to go to the settings of the database.

Having this is to ON, can cause a performance issues and more entries in the log.  Below is an example of what entries you may see in your log.

In the below image you can see the database that has been flagged as having been closed automatically.

This is something new in Azure Data Studio.  SQL Server Management studio does not display this, as shown in the image below.

Once you query a table, the “Auto Closed” message will go away.  The reason it will go away is because the database is no longer closed.

Now that we have covered what Auto Close is and how it will be displayed in Azure Data Studio, you might be wondering whether or not it should be turned ON.  The answer is NO…you should not turn this on.  I think Pinal Dave summed it up the best in the screenshot of something from one of his blog posts, the screenshot is below.  This is the link to this page.

In addition to what Pinal says, there many others that also recommend that this setting be turned OFF.  This post really wasn’t about the inner workings of the Auto Close setting, but I felt it was important to give a brief overview of what it is.  Read some of the other posts and make up your own mind, but keep in mind it is considered a best practice to leave this off.

Thanks for visiting my blog!!