Category: Blog

  • Advice I Like: Focus on what’s important

    Don’t let someone else’s urgency becomes your emergency. In fact, don’t be governed by the urgent of any sort. Focus on the important. The urgent is a tyrant. – from Excellent Advice for Living

    I try to set my life up to be fairly relaxed. A little chaotically busy, but relaxed. I try to stay ahead of work, plan things, get them prepped, and beat my milestones, at work or at home.

    However.

    As some people might say, life happens. Others might use a different 4 letter word, but I’ve liked life. As John Lennon says: Life is what happens to you while you’re busy making other plans.

    I do try to help others and accommodate them, but another’s emergency isn’t mine. I am here for support, and to listen, but encroaching on my wallet or my time is something I have to choose to give you. Sometimes I might, but sometimes I might not. Ultimately. I don’t want to get jerked around by others, at work or in life.

    I try to remember what’s important, which might not be someone else’s thing. This might mean previous plans take precedence. Or it might mean that I decide to help with your emergency. The important thing is the important thing.

    I’ve been posting New Words on Fridays from a book I was reading, however, a friend thought they were a little depressing. They should be as they are obscure sorrows. I like them because they make me think.

    To counter-balance those, I’m adding in thoughts on advice, mostly from Kevin Kelley’s book. You can read all these posts under the advice tag.

  • Modifying a Trigger to Capture More Info: #SQLNewBlogger

    I had someone ask me about using triggers to detect changes in their tables. This is a second post looking at triggers, in this case, modifying my trigger to detect more changes and using that information.

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    The Setup

    We’re using the same table from the last post.  This is the dbo.Customer table with a PK and 5 other fields.

    In this case we want to track the changes to an email and capture what those changes are. In other words, if I update the email from ‘sjones@sqlservercentral.com’ to ‘steve.jones@red-gate.com’, I want to capture

    To do this, let’s modify our trigger. We can still test if the field is updated with UPDATE(). We did this in the last post.

    This will let us know that the column changes by returning a boolean. If this is true, we want to insert the new values into our logger. We also want to capture the old value. These values are stored in the inserted and deleted tables, which are available in a trigger. I’ll use a join between these on the PK to get the same data from both.

    I’m also using a query with these tables because more than one row can be updated and we want to capture all the changes.

    Here is my new trigger, with the OR ALTER added to the code.

    CREATE OR ALTER TRIGGER Customer_tru ON dbo.Customer FOR UPDATE
    AS
    BEGIN
         IF UPDATE(CustomerName)
             INSERT dbo.logger (logdate, logmsg) VALUES (DEFAULT, 'dbo.Customer.CustomerName changed')
         IF UPDATE(AddressKey)
             INSERT dbo.logger (logdate, logmsg) VALUES (DEFAULT, 'dbo.Customer.AddressKey changed')
         IF UPDATE(CustomerStatus)
             INSERT dbo.logger (logdate, logmsg) VALUES (DEFAULT, 'dbo.Customer.CustomerStatus changed')
         IF UPDATE(CustomerContact)
             INSERT dbo.logger (logdate, logmsg) VALUES (DEFAULT, 'dbo.Customer.CustomerContact changed')
         IF UPDATE(ContactEmail)
         BEGIN
             INSERT dbo.logger (logdate, logmsg) 
             SELECT GETDATE(), 'ContactEmail updated from ' + d.ContactEmail + ' to ' + i.ContactEmail 
              FROM inserted i
              INNER JOIN Deleted d ON i.CustomerID = d.CustomerID
         END
    END

    This is mostly the same code, but now I’ve changed the last conditional test. If the email is updated, I want to query the inserted and deleted tables and create a log message. This is the type of thing I’ve seen often in systems, and while it’s not a great pattern, it does let me capture some information. There are some problems with this, I’ll discuss in the next post.

    We can see below that when I run this code, I get the updated captured and logged.

    2025-05_0230

    This post has introduced a few new things, the inserted and deleted tables, which I didn’t discuss in the last post. However, they are useful when you want to capture information affected in triggers, which can be more than one row. Using these tables helps you set up triggers that handle multiple changes.

    There are problems with this trigger, mainly with NULLs, potential performance, and architecture in what is captured, but we’ll address those in the future.

    SQL New Blogger

    This post looks at enhancing a previous post and providing more information. You (hopefully) learn from your work, from both feedback  and experiments, and you should modify your thinking and work. This shows how I’ve adapted something I did previously, which is a skill we all need.

    This was a 20-30 minute post for me. You could likely do it in a similar amount of time.

  • T-SQL Tuesday #187–Solving Problems

    This month we have a great invite from Joe Fleming, a first time host of T-SQL Tuesday. Joe reached out when I requested some hosts and I’m glad he did. He’s got a great challenge for people and I’ll answer in two ways, for work and non-work.

    I manage the T-SQL Tuesday site and I’m always looking for hosts, so if you want to host one month from your blog, send me a note on Twitter, Blue Sky, or at SQL Server Central.

    Troubleshooting SQL Server

    In my career, I’ve had all sorts of issues come up. Here’s a description of one of the stranger issues. This isn’t the exact issue, but it was similar to this.

    A user reported they couldn’t log into the server. They were logged on earlier, but can’t connect now through an application. What could be the problem?

    When looking at this type of issue, I usually think there is some sort of network issue here, or perhaps a service issue. My  thoughts are:

    • Can I connect? Or can others? (trying to determine if it’s this user)
    • Can this user connect with another app that might give an error message?
    • Is the server instance up? (check the basics and isolate if this is networking)
    • Has this login had a change to permissions/password/etc. Perhaps an AD change.
    • Has something else changed on the server?
    • Has something changed on this user’s machine?

    At some point, I’ll isolate where the issue is and determine how to fix it. In this case, I managed to determine the user was a DBA that was playing with a logon trigger and locked themselves out.

    The UTV Won’t Move

    On the ranch we have to learn to handle lots of things ourselves. YouTube has been a boon, but it’s also a bit of common sense and problem solving that we need to get things done. It can be hard to get people out to the ranch, especially for small things.

    Sometimes big things.

    Awhile back I came back home from a trip to find the spare UTV we have in one of the fields. I asked what had happened and a kid said that it died.

    That’s not a good description, so I asked how it died. What was going on? what was happening? This kid said they’d stopped the vehicle to do something and put it park. When they went to shift into drive, it wouldn’t move.

    Did the engine run?

    Yes, but the UTV didn’t move.

    Now that I had a better story, I could debug further. I knew that it ran and went out to start it myself. Sure enough, it starts and the shifter didn’t do anything, but it felt loose.

    Sometimes hands-on helps. I knew immediately a cable had broken.

    First thing, get this out of the field. I knew there was a way to shift it without the cable, I just had to figure out. (YouTube to the rescue). Once I did that, it’s research to figure out how hard this is to replace and where I can get the part.

    I logically move through the steps of how can I practically get things done.

    From here, I saw someone talk about this on YT and show me this isn’t hard. I learned how to shift into Drive with a pair of vice grips, got it up to the house, and I found the part online. I ordered it, send the YT link to the kids, and tasked them with fixing the cable.

    They did, after some problem solving from me.

  • Monday Monitor Tips: Customizing Data Retention

    One of the biggest challenges with monitoring data is managing the volume over time. Lots of bespoke/home-grown solutions don’t do this well, and some commercial products have a gross approach that might not meet your needs.

    Customers constantly ask me about this, so here’s a quick tip on how you can manage data retention in Redgate Monitor.

    This is part of a series of posts on Redgate Monitor. Click to see the other posts.

    Checking the Configuration

    As with most things in Redgate Monitor, this is a config item. In your Redgate Monitor solution (or on the public demo site), you can find the configuration gear icon in the upper right.

    2025-05_0114

    Click this and you get to the settings page. Scroll down to the Preferences area and there is a Data retention settings link. Click that.

    2025-05_0116

    You will get to the Data retention settings page (public site), which has a few sections at the top. You will be setting this per Base Monitor, using the drop down at the top.

    Scroll below these to the data retention section, which you see at the bottom:

    2025-05_0117

    In this section, you see quite a few different sections. I’m showing the trend data below.

    2025-05_0118

    There are sections for

    • trend data- long term data for understanding how performance and baselines work
    • performance troubleshooting data – query, waits, plan, etc. data

    Each of these sections is described, along with where the data is displayed. You can see that in the image above.

    To the right of these, are the retention settings. I’ve got an image of the first few items. You can see the time for which to retain data and then the current size of that data.

    2025-05_0119

    You can set a fairly granular level of retention for data here, broken out by the various data elements we capture.

    The choices for retention are shown below, including indefinitely (be careful of this one).

    2025-05_0120

    We have this documented, along with what we think are good defaults on this page. For example, we keep top query data for only one week, since this is a lot of data. However, if you want more time, then set it to something that works for you.

    Summary

    Data management is always a challenge, both in production databases and in our monitoring systems. Redgate Monitor gives you lots of choices, and those can vary by Base Monitor, so if you have a BM in the cloud doing some stuff and one on premise doing other things, you can set separate retention settings. That can be handy, especially when the cost of storing things can vary dramatically.

    Watch this over time and adjust settings as needed to keep your system performing optimally.

    Redgate Monitor is a world class monitoring solution for your database estate. Download a trial today and see how it can help you manage your estate more efficiently.