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