ADS: New Database

Regardless of what tool we are using, SQL Server Management Studio or Azure Data Studio, the need to create new databases is always present. Using Transact SQL is an option in both tools.  What is not an option in both tools is to right click and to go “New Database”.  This has been in SSMS for many years, however it is NOT present in Azure Data Studio.

Below you can see what the menu options are when you right click on databases in SSMS.  The New Database option is right at the top.

 

Now lets move on to Azure Data Studio.  When you right click on a server you will have a number of options, including new query, refresh and disconnect.  What you do not see is “Delete Database”.

As with a great deal of functionality in Azure Data Studio, the ability to right click on a server and create a new database comes with the installation of an extension.  In this case the extension was created by Keven Cunnane, It is pretty simple to install and cost the same as ADS, nothing.  This extension is currently not in “Preview” mode.  It is currently at version 1.0.0.

To install you will need to click the install button when looking at the extension documentation in Azure Data Studio.

Once you do, you will be taken to the location to download the .VSIX file.  You will need to download it and save to a location where it won’t be deleted or overwritten. To install, simply click on “Install Extension from .VSIX package” on the File menu.

Once you do you will see in the lower right corner that the extension has been installed.  A restart of Azure Data Studio is not required.  Now when you right click server, what do you see?  Well..you will see that nothing changed.  You will need to right click on Databases under the connection.

Once you click “New Database” you will not see the same dialog box you will see in SSMS.  What you will see is something like what is in the image below.  In the box you will enter the name of the new database.

Then hit enter and assuming you have the proper rights, ADS will create the database.  You will not be able to enter any of the settings we often change to accommodate the specific needs of the database or system.  This includes things like file location, recovery model, file growth rate and many more. With this, you will either need to use TSQL to adjust some of the settings or use SSMS.  This method of creating a database will depend on the defaults for all the settings.

Overall this is a good extension although it depends heavily on default database settings.  I still prefer to use TSQL when creating a database, however this is a nice simple method to use as well.

Here is a list of a number of available extensions, click here.  This list does not include all the extensions that are available but is still a nice list.

Thanks for visiting my blog!!

ADS: Demo Mode Extension

Through out the year I present a lot of sessions on SQL Server and related technologies. These take place at user groups(9 in 2019), SQL Saturdays(14 in 2019), training sessions at work and teaching the SQL Server certification courses from Microsoft.  With these many different presentations there are differences in the screen sizes and room sizes.

When presenting, setting the demos up in a way that will allow all attendees to easily see the code can be a bit of a challenge sometimes. To accomplish this presenters have several tools available to them.

Tools commonly used

      • ZoomIt – This is a free third party tool that I have been using for a few years
      • Windows 10 Zoom feature
      • Increase the font of the code window in SQL Server Management Studio or Azure Data Studio
      • Use the Demo Mode extension in Azure Data Studio
      • A number of other tools

While I would love to list the pros and cons of each, that really isn’t the focus of this blog post.  Recently an extension for Azure Data Studio was released by Drew Skwiers-Koballa that I think is a great addition to the list of available tools.

The first thing to do is to install the extension.  To do this, you will need to download the .vsix file.  In order to find the extension, you can type the word “Demo” in the extension search box.  Taking a small step back, if you are not sure how to get to the extensions, you can open the extensions by using the menu item under the View menu.

To download the file you will need to click the install button in Azure Data Studio when looking at the documentation of the extension.

When you download the file, place it in a location that will be secure and the file will not be overwritten.  Once saved, to install it, go to the “Install Extension .VSIX package” menu item under the file menu.  You will need to restart Azure Data Studio when the install is complete.  Please remember, this is extension is still marked as being a Preview.  Given that, things could change with the next release.

Now that it is installed, let’s go over what it does.  This part is pretty simple, when enabled, the font in the query window will be come larger and when disabled the font will become the original size.

The two images below show the font with Demo Mode enabled and disabled.  The first image is disabled, while the second has Demo Mode enabled. Notice that the only thing that changed is the font size of the query.

When Demo Mode is enabled the only thing on the screen that will change is the font size of the query.  Everything else will remain the same size.

To enable\disable the extension you will need to do one of two things.  First, you can use the Command Pallett.  Type “Demo Mode” into the search box.  Two options will be returned, Enable and Disable Demo Mode.  This can be seen in the image below.

The second option is to click the Enable\Disable Demo Mode button that is located in the lower left corner of Azure Data Studio.  I personally like this option because it is very easy to use.  By default neither of these options has a keyboard short cut assigned to it.  However, under File–>Preferences–>Keyboard Shortcuts, you can add the short cut key or key combination that will work for you.

You may be asking yourself where does the extension get the font sizes to use.  When the Demo Mode extension is installed, three settings are added.  Two of these settings identify the font size to use when the extension is enabled or disabled.  See the image below.

The Demomode: Demo Font Size setting is what font size ADS will use when the Demo Mode extension is enabled.  As expected, you would want this to be bigger than the Original Font Size, which is just below it.  This represents the font size with the extension is disabled.

The third option will allow Azure Data Studio to send confidential about the usage of the extension.  As you can see with the presence of a checkbox, this is something you can option out of if you like.  The documentation can be found here. This is what the documentation actually states:

“enables anonymous usage data to be sent to an online service”

The documentation also goes on to state the following:

“The extension telemetry sends usage data anonymously to an Application Insights instance. Machine information, such as operating system or general location, may be shared with the general public in aggregate. Your information will not be sold to any third parties. For more on the collection of telemetry in this extension, read more here or ask questions here”

Please read through these very carefully to determine of this is something you would like to opt out of.

Under the hood, when this extension is enabled, it changes the Editor: Font Size to be the same as the Demo: Font Size setting for the extension.  If you close Azure Data Studio while the extension is enabled, the font setting will persist.

What happens if there are more than one query window open?  Well, the extension will apply the font setting to all query windows that are open.  I also noticed that if the extension is enabled and you close settings, the current font size will also persist.

Another question that comes to mind is will this setting only apply to queries?  The answer is no. This extension will also have an impact on the font in Notebooks.  If you look at the image below you will see what the text will look like with the extension enabled and disabled.  Notice the difference in size of the box the text will be entered into.  Of course this assumes that the two font settings for the extension are different sizes.  In a notebook, this font change only applies to when text is being entered, it will not have an impact on the look of the text that will be displayed.  I checked the Terminal that will be used for PowerShell and the use of the extension does not have any effect on the size of the font.

If you open Settings and you only get json, earlier I completed a blog post on how to open the Settings in json rather than the UI.  Here is the link to that blog post.  In the settings.json file, the Demo Mode extension will look like below.

I like this new extension and plan on utilizing it for all my sessions that use Azure Data Studio.  For additional information you can go to the documentation. I would like to point out that while this extension has a target audience of people who do presentations, it also has another audience.  Sometimes, I just need the font to be slightly bigger for a temporary reason, like I am tired and the eyes just can’t focus as well as normal.  I can use this extension to make that much easier.

For more information about  Drew, the developer of this extension, you can go to his blog, https://www.drewsk.tech/.  Also he has a nice presentation on developing extensions.  If you get a chance to hear this at your local user group or SQL Saturday, make sure you go, it is a very nice session!

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 – 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!!!

 

 

 

 

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!!

 

 

 

Azure Data Studio – Profiler

For many years DBAs have been using Profiler to help with troubleshooting issues.   This involved opening a second application name SQL Server Profiler.  With Azure Data Studio we can now stay in one application by utilizing the SQL Server Profiler extension. Like most extensions, this one is still in preview and could change before final release.

The documentation states this, “The SQL Server Profiler extension provides a simple SQL Server tracing solution similar to SSMS Profiler except built using XEvents.”.  This means that the SQL Server Profiler extension is using Extended Events instead of trace.

As stated earlier this is an extension, therefore will need to be installed.  This is a pretty easy process.  The first thing we need to do is to open the extensions window.  This can be done under the View menu.

View –> Extensions

Once the extension window opens, do a search on “Profiler”.  When you do you will see this.

Once you find it, click the Install button you see above.  This extension was created by Microsoft and is a very fast install.  In addition, if you look at the above image, you will see a star in the upper left corner, this means that the extension is recommended by Azure Data Studio.  You will not need to restart Azure Data Studio once the installation is complete.

The shortcut of the Profiler extension is ALT + p.  If you use the short cut before you have installed the extension, you will still see something that appears to be profiler even though it is not.  The image below is a screenshot.  Notice that the tab says Profiler, yet the sessions are all the Extended Events sessions that are on the server I am connected to, so this really isn’t Profiler, even though it might look like it. Just a side note, if you have the proper permissions, you can start and stop Extended Event sessions here.

Once the Profiler Extension is installed there are two ways to open it.  The first one and the easiest one is to use the shortcut, ALT + p.  The second method is to utilize the Command Palett.  This can be found under the View menu, should be the top item. When you open it, type the word “profiler” in the search and it will appear as below.

Once you open Profiler, if you do not have an active connection, you will be asked to create one.  Then you will be taken to the screen below, which is the same screen you will be taken to if you have an active connection.

You will not be able to pick the events like you can in Profiler.  At this point in time, it appears that you are limited to two profiles, TQL_OnPrem and Standard_OnPrem.  Notice both say OnPrem, there is a third option when you connect to an Azure SQL Databases, Standard_Azure.  Although there are three, you will only see the Standard_Azure template when connected to an Azure SQL Database.

Earlier I mentioned that the Profiler is built on Extended Events.  This is how you can see if a current session is running.  Extended Events information is stored in a number of system tables and views.  To see what Extended Events sessions are currently running you can use the code below.

SELECT *
FROM sys.dm_xe_sessions;

Your results will look similar to what is below.

Once I start the Profiler trace, I will see an additional session.  Notice that the name starts with ADS.  This will be the name you will see if you are using the TSQL Templete, ADS_TSQL_OnPrem.  Once you stop the trace, this entry will disappear.

 

If you look at Extended Events in SQL Server Management Studio you will see two now sessions.

These names match up with the names you will see when you start Profiler in Azure Data Studio, just with ADS_  at the beginning.

 

If you have used the XEvents Profiler in SQL Server Management Studio, these might look familiar.  The sessions that XEvents Profiler creates are exactly the same as the ones created by the ADS Profiler, just a slightly different name.  The image below shows that ADS and SSMS sessions that are the same.

 

Once the session starts you will see this across the top of the grid.

Going left to right, let’s briefly cover each item

Select Session:  This has a drop down box to the right.  When a session is running, this drop down box is not available.  However, if you stop the session, you will be able to pick a new sessions.  The options include the two mentioned above as well as any Extended Event sessions that are currently on the server

Start\Stop\Pause:  These do exactly as you would think. Start a sessions, stop as session and pause a session

Filter\Clear Filter: This allows you to place a filter on the results.  Here you can also save the filer, however I was struggling to get this to work properly.

Select View:  Like the session label mentioned above, this also has a drop box to the right.  However, for this, the items in the drop down list simply change what is displayed.  When changing this, you will not only see a change the data that get’s captured, you will also see changes in the columns.

Autoscroll: This turns of the autoscroll

Clear Data:  This is the farthest one to the right.  Like a few of the other’s, this does exactly what it says it does, clears data.

Once you start collecting data, you will see a grid.  If you look next to the EventClass header you will see a little green arrow.  This is supposted to sort the data in a manny you decide.  What I have found it that this works on some columns, while appearing that is doesn’t work on others.

If you select a line in the grid, you will then see the Text and Details tabs in the bottom half.  Similar to this screenshot.  The text will simply return the query that was running, like below.

The Details tab will look similar to below. It will display the data for a the record that is selected in the grid.

There, now you are ready to use the Profiler extension.  One of the limitations is that you do not have an option of where to save it.  Just like the XEvent profiler in SQL Server Management Studio, the data here is somewhat temporary.

Earlier, I mentioned filters on the Profiler.  While they do exist and they are easy to work with, I would be a good idea to know where the filter stored.  The answer, is this filter is storted in the settings.json for Azure Data Studio. To see this we need to review the json file.  The settings window can be opened by using the Preferences menu item under File.  When you do a search for the word “Profiler” you will get the results as you can see below.

All the settings will require you work with the settings.json file.  To get there simply click the link. In the image below, you can see that there is a setting that was saved by using the save functionality in the filters form.  In this case the name is default, the field I want to filter it on is SPID and looking for a value equal to 51.  For the operator, 0 is the value for equal, while the value for not equal to is 1.

You now have enough information to start using the Profiler extension.  Over all, it isn’t bad, however because this is a function of a client application caution must be used.  If there are a number of folks in your environment that have Azure Data Studio installed, you could have a number of folks running this at the same time.  Given that the Profiler Extension is based on Extended Events, you should be aware that for the most part Extended Events are very lightweight, however if many people are doing this, there is a risk of causing a performance issue.  So use…but use with a certain amount of caution.

Thank you for visiting my blog!!

 

 

 

 

 

 

 

 

 

 

 

 

Azure Data Studio – Poor SQL Extension

When I write T-SQL, I attempt to make it as readable as possible. In order to do this, I must follow best practices for formatting.  There are a number of online formatters that can help you out, which you would depend on if using SQL Server Management Studio.  However, with Azure Data Studio that is no longer that case.  There is an extension named Poor SQL Formatter that we can use.  Like most extensions for Azure Data Studio, this extension is currently in preview.  Despite that, it can still be very useful.

Installing the Extension

To install the extension, the first thing we need to do if find it.  This can be done by clicking the Extension item under the View menu.  Once the Extension window appears, simply type the work “poor” in the search window.

When you click install, you will be taken to the GitHub page for the extension.  You will need to download the vsix file.  You will need to place it in a location that will not be overwritten or deleted.
Once you have downloaded the file, you will now need to install it.  This can be done by going to the File menu and clicking “Install extension from VSIX package”.  Then you will need to navigate to the location you placed the file.  When you locate the file, Azure Data Studio will then install it.  You will see a popup in the lower right corner that the install is complete.
Once installed, this extension does not require a restart of Azure Data Studio.
What does this Extension Do?
According to the documentation in ADS the extension provides the following help with formatting TSQL.  These are copied directly from the documentation.
      • poorSql.tabIndent: Use tabs for indentation?
      • poorSql.numIndentSpaces: Number of spaces to use when indenting. Ignored if tabIndent is true.
      • poorSql.maxLineWidth: Max characters per line.
      • poorSql.statementBreaks: Number of line breaks between statements.
      • poorSql.clauseBreaks: Number of line breaks between clauses within a statement.
      • poorSql.expandCommaLists: Expand comma-delimited lists onto new lines?
      • poorSql.trailingCommas: Should commas be at the end of lines?
      • poorSql.spaceAfterExpandedComma: Should a space be added after commas?
      • poorSql.expandBooleanExpressions: Should boolean operators cause a linebreak?
      • poorSql.expandCaseStatements: Should WHEN and THEN expressions in a CASE statement cause a linebreak?
      • poorSql.expandBetweenConditions: Should arguments of BETWEEN expressions cause linebreaks?
      • poorSql.expandInLists: Should IN lists be split by linebreaks?
      • poorSql.breakJoinOnSections: Should the ON section of a JOIN clause cause a linebreak?
      • poorSql.uppercaseKeywords: Should keywords be automatically uppercased?
      • poorSql.keywordStandardization: Should less-common keywords be replaced with common alternatives? (Caution: only safe for T-SQL)
      • poorSql.obfuscate.randomizeKeywordCase: Obfuscation: should the case of keywords be randomized?
      • poorSql.obfuscate.randomizeLineLengths: Obfuscation: should line lengths be randomized?
      • poorSql.obfuscate.preserveComments: Obfuscation: should comments be preserved?
      • poorSql.obfuscate.enableKeywordSubstitution: Obfuscation: allow common keywords to be replaced with less common alternatives? (Caution: only safe for T-SQL)

Now that the extension is installed, you will see the above items in Settings. You can get to settings under the File menu, File –> Preferences –> Settings.  The best way to find all the settings related to this extension is to do a search on the word “poor”. Most of these are Boolean settings, True or False.  However there are some that are not.  The settings below are the ones that are not Boolean and the default value is also listed.

      • poorSql.numIndentSpaces is set to 4
      • poorSql.maxLineWidth is set to 999
      • poorSql.clauseBreaks is set to 1
      • poorSql.statementBreaks is set to 2

There are a few settings that are not enabled by default.  These are listed below.  Something to keep in mind, the extension is still in preview and could change with the final release.

      • poorSql.trailingCommas
      • poorSql.tabIndent
      • poorSql.obfuscate.enableKeywordSubstitution
      • poorSql.keywordStandardization
      • poorSql.expandInLists
      • poorSql.expandBetweenConditions
Now that it is installed, how do I use it?
If you look at the code below, you may see a few coding issues. these are issues I believe make it more difficult to read the code.
      • Not all key words a capitalized
      • The columns in the SELECT are kind of sloppy.  There are three columns in one line with the other two are the only column in the line
      • The CASE is more difficult to read because it is on a single line
      • The joins are hard to read because they are not organized in a readable manner
Below is the unformatted code.
select p.Class
    , p.Color, p.ProductID, p.ProductNumber,
p.Size
    , CASE WHEN p.color = ‘Black’THEN ‘BL’ END
from Production.Product p INNER JOIN Sales.SalesOrderDetail o ON p.ProductID = o.ProductID
inner JOIN sales.SalesOrderHeader h ON o.SalesOrderID = h.SalesOrderID
WHERE color = ‘black’
In order to use the PoorSQL extension, you will need to use the Command Pallet.  The Command Pallet can be found under the View menu. Once you click it you will see something similar to the image below.  The Command Pallet is a location that lists out many commands that we will use.  As more extensions are added, many of them place commands here to make it easier to use.  The Command Pallet if used can make our lives just a bit easier.
To find the PoorSQL commands, just type the word Poor into the search box and you will see the commands in the screenshot below.
If you pick the bottom one, SQL: Obfuscate, this will apply all the settings that have Obfuscate in the name.  If you choose the top option, SQL: Format, it will apply all the other settings, ones that don’t have Obfuscate in the title.
Once you have made a choice and clicked on it, all the appropriate settings will be allied. In the case of the code above, I chose SQL:Format.
SELECT p.Class
    , p.Color
    , p.ProductID
    , p.ProductNumber
    , p.Size
    , CASE
        WHEN p.color = ‘Black’
            THEN ‘BL’
        END
FROM Production.Product p
INNER JOIN Sales.SalesOrderDetail o
    ON p.ProductID = o.ProductID
INNER JOIN sales.SalesOrderHeader h
    ON o.SalesOrderID = h.SalesOrderID
WHERE color = ‘black’
After utilizing SQL:Format in the Poor SQL Formatter, the code is much easier to read and did not take very long to apply the formatting rules.  Of course being easier to read is my opinion, you will have to make that determination for yourself.
Overall, I do like this extension and would recommend to install it.  However, please keep in mind that this in still in Preview and may change before the official release.
Thanks for visiting my blog!!!

ADS – Server Groups

Azure Data Studio has a ton of great features. Of course some I like more than others, but Server Groups is something I really like.  The team I am currently part of manages almost 200 production SQL Servers.  However we do find ourselves working on Dev and QA servers as well, greatly increasing the numbers of servers where could potentially work with.  This greatly increases the likelihood of making a mistake and running the code on the wrong server.   However, even with just a few servers, it would be nice to be able to group the connections to make it a bit easier.  Server Groups are not new, it has been in SQL Server Management Studio for quite some time.

Create a New Server Group

Creating a new server group is pretty easy.  When in the servers window, float your cursor in the upper right corner and three buttons will appear.  These buttons are, from left to right, New Connection, New Server Group and Show Active Connections.  The middle one is the one we want.

Once you do, a very simple window will open up.  This window may appear on the right side of your screen, which is by default where it will appear.  To create a group you only need three bits of information, the group name, group description and color.

Once you click “OK”, you will now see your server group.  You will see the description when you float your cursor over the group.

Now that we have our server group, it is time to add a connection to that group.  This is pretty easy as well.  When creating a new connection, one of the properties you will be asked to fill out, although not required, is the Server Group.

What if it is an existing connection I want to move to the new group?  This is even easier.  When in the connections window, simply drag the connection to the group header that you want to move it to.

Add a Server Connection to a Group

Now that we have the group, we can begin to add server connections to the group.  This can be done simply by right clicking on the group and then clicking, New Connection.  This will open the New Connection window with the server group already filled in.

If the connection already exists and would like to add it to the new group.  All you need to do is click and drag the connection to the header of the group.

Changing settings of an Existing Group

If you attempt to right click on a group, you will get three options.

      • New Connection
      • Edit Server group
      • Delete group

As mentioned earlier, the New connection will take you to the new connection window with the server group already filled in, although you can still change it if you like.

Edit Server group will take you to the same window that you used to create the group.  This allows you to change the Name, Description and color.

However, what if the setting I want to change isn’t in the list.  For this you will need to go to Settings.  This can be found under the File menu.

File —> Preferences —> Settings

When you are there, type group into the search box and a number of settings will appear. The ones we are looking for are under Data.  As highlighted below.

Notice there are four settings.  Of which, only two can be modified here.

Server Group: Auto Expand – will expand the server groups automatically

SQL: Tab Color Mode – This will change the color of the tab to the color of the server group it is in.  I complete another blog post on the details of how this works and how to change it.  The post can be found here.

That leaves Server Group: Colors and Data Source: Connection Groups.  These will need to be modified in a much different way.  These will involve editing the settings.json file.

The settings.json file can be found here:

C:\Users\daveb\AppData\Roaming\azuredatastudio\User

According to Microsoft’s web site the file can be found in this location:

%APPDATA%\azuredatastudio\User\settings.json

Although knowing the location is good, we really don’t need it.  Azure Data Studio provides a link that will open the file in ADS so we can modify it.

Reading the Json File

Let’s take a few minutes to go over how to read the json file.  While this is not a json post, knowing how to read what you see is important.  We will discuss only the two settings that are relevant to this post.  While reading this, please keep in mind I am not a json expert. Jim Dorame has a really nice SQL Saturday presentation titled “Json for the Data Mortals” that is very good.  He presented it at the SQL Saturday in Madison, WI this past year.  The presentation can be found here.  The image below is a screenshot of what you might see if you clicked either one of the links in the settings window.

If you look above, you will see these []. These define an array.  In this case the array is named: dataource.connectiongroups.  Under that you will begin to see these:{}.  These will define each object within the array. In this case there are four items.  Finally within each object you can find the properties.

Notice that each object has an ID as well as the ParentID.  The ParentID can be used to create a hierarchy of the server group.  This could be useful in many ways.  For example, you have a ton of SQL Servers, some in North America and some in Europe.  You could create a top level group named Produciton and then under that of two subgroups, North America and Europe.  Similar to what you see below.

Now let’s take a quick look at the Json.  In the image below, you will notice that the parentID for the North America object is the same as the ID for the Production object.  If you wanted to move the North America group to another top level group, you will need to find the ID of that new group and paste it into the ParentID setting of the North America group.  When you exit out of the settings.json file, you will be asked to save the file.  Of course you will want to save it.  If you do change it, keep in mind that the setting won’t take effect until Azure Data Studio is restarted.

Another property you may want to change is the group color.  When creating the server group, you only have a few options.

Well, what do I do if either I don’t like the colors or I have more groups that colors.  Again, this is where the settings.json file will come into play.

For each group you will see a color setting.  All you will need to do is find the hexadecimal number for the color you are wanting to use and place it into this property.  Here is a few good links, HTMLColors and Color-Hex.

Let’s say I wanted a group to be purple.  I could find the hex number, which is #800080 and paste it in the settings.json file as you can see below.

After restarting Azure Data Studio, this is what you will see, North America is now purple.

Now you have all the information to create groups to help you manage you servers.

Thanks for visiting my blog!!!

 

 

 

 

ADS – How to Mark a Tab as Production or QA

Have you ever been in an environment where you worked with both DEV\QA servers and Production servers?  Of course you have, we all have.  However, being in such an environment brings a certain level of risk.  We all try to be very careful to run any code we are asked to run on the correct server and in the correct environment.  Despite all of our checks and our Due diligence, we are still human and do make a mistake from time to time.  Azure Data Studio has a nice feature that will allows us to change the color of tabs based on the environment the server is in.  The image below is an example of what it would look like.

Setting this up can easily be done in two steps, creating Server Groups with different colors and changing the tab color property in Settings.

Create a New Server Group

Creating a new server group is pretty easy.  When in the servers window, float your cursor in the upper right corner and three buttons will appear.  These buttons are, from left to right, New Connection, New Server Group and Show Active Connections.  The middle one is the one we want.

Once you do, a very simple window will open up.  This window may appear on the right side of your screen, which is by default where it will appear.  To create a group you only need three bits of information, the group name, group description and color.

Once you click “OK”, you will now see your server group.  You will see the description when you float your cursor over the group.

Now that we have our server group, it is time to add a connection to that group.  This is pretty easy as well.  When creating a new connection, one of the properties you will be asked to fill out, although not required, is the Server Group.

What about if it is an existing connection?  This is even easier.  When in the connections window, simply drag the connection to the group header that you want to move it to.

Tab Settings

Now that we have our groups, it is time to set Azure Data Studio up so the query tabs will match the group color, similar to the image below.

To do this we need to change a property.  The property can easily be found by first going to Settings.  This can be found under the File menu.

File —> Preferences —> Settings

Once there, do a search on “Tab Color” and the proper setting will be returned.  The name of the setting is SQL: Tab Color Mode.

In the drop down box there are three options.

      •  Off
      • Border
      • Fill

Off is what it is…Off.  Border will place a colored line that matches the group color.  Fill turns the entire tab the color of the group.  If you change the setting, you should restart Azure Data Studio.

This is what the Border setting will look like.  Notice that there is a line across the top of the tab.

Now we have an additional check we can make to help us assure we are in the proper environment.

Thanks for visiting by blog!!!