Category: Blog

  • Can I Change a Primary Key Value? #SQLNewBlogger

    I heard someone say recently that you can’t change a primary key value in a row. That’s not the case, so I decided to show a quick proof of that.

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

    The Scenario

    Let’s set up a simple table with some data.

    CREATE TABLE PKChangeTest (
    ImportantNumber VARCHAR(20) NOT NULL CONSTRAINT PKChangeTestPK PRIMARY KEY
    , CustomerName VARCHAR(50)
    , StatusValue INT)
    GO
    INSERT dbo.PKChangeTest
       (ImportantNumber, CustomerName, StatusValue)
    VALUES
       ('1234567', 'Steve', 1)
    ,  ('2345678', 'Andy', 1)
    ,  ('3456789', 'Brian', 1)
    ,  ('1235667', 'Leon', 1)
    ,  ('1265567', 'Dave', 1)
    ,  ('9914567', 'Bill', 1)
    GO

    If I look at this table, I have some unique numbers making up the PKs. If I select from the table, I can see the data.

    2025-04_0117

    Now, let’s change some data. I’ll change the PK values with a few statements. Then I’ll select from the table, and we will see things changed.

    2025-04_0118

    The ImportantNumber for both Bill and Steve have changed. These are PK modifications.

    We can change a PK value. These are not set in stone once inserted.

    SQL New Blogger

    This is a short look at something that’s a myth among some people. When I heard someone say this, I knew I needed to prove this. The scenario took just about 5 minutes to set up (even without AI), and then it was another 10 minutes to structure and write this post.  I actually have 2 more ideas from this on things I can show to prove how PKs work and are malleable.

    You can do the same thing. When you wonder about something, or hear something that isn’t true from others, prove it. And blog about it.

  • Monday Monitor Tips: Finding the Hostname for Queries

    I was chatting with a customer recently and they wanted to know which host was sending in queries that were causing problems in real time. This post looks at where you can find the hostname for running queries, which is in two places.

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

    The Server Overview

    There are two places where you can see the host name. From the server overview, you can go to the current activity, or the new Query Executions tab in preview.

    Current Activity

    In the server overview, there is a lot of data, but most people scroll down to see the list of queries, such as this list from the ssc-db-n3 instance.

    2025-04_0089

    There is the database and lots of data, but no hostname. The reason is that these are aggregates. Each of these queries has run many times, possibly from different hosts. This is a historical view.

    The better way to look for details on certain problem queries now is to look for current activity. I’ve zoomed in and highlighted this item below.

    2025-04_0090

    If I click that, I get an sp_who, or sp_whoisActive view of the server, and I can see the logins listed here. That’s helpful.

    2025-04_0091

    Still no hostname, but if I pick a query from a login, and see the details, I see this view.

    2025-04_0092

    In the lower left corner, I get the hostname. I’ve zoomed in below.

    2025-04_0093

    We could add that in the main box, but we’re trying to surface the most important info, and for most of our customers, that isn’t the hostname. However, we have added it in the detail.

    If you’re like it in the main box, or would like to choose which fields are there (maybe host and not program?), send us a note to your rep or to sales@red-gate.com.

    Query Executions

    For some of our servers, we have a new Query Executions tab that uses Extended Events to get some data. The Workload02 system has this enabled. You can see the tab at the top, and then the view of this below.

    Query Execution tabs

    If I zoom in to the lower right, you can see the hostname as part of the details for query executions, along with other data. As you are examining the details of those queries which have run for over 5 seconds, you can get the metadata about the host, application, and more.

    Zoom in to hostname details

    Summary

    Hostnames are available, you just need to learn where to look. Hence this post. Hopefully this gives you a quick tip on how to find them.

    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.

  • A New Word: Immerensis

    immerensis – n.  the maddening inability to understand the reasons why someone loves you – almost as if you’re selling them a used car that you know has a ton of problems and requires daily tinkering just to get it to run normally, but no matter how much you try to warn them, they seem all the more eager to hop behind the wheel and see where this puppy can go.

    Most people likely go through this, unless they are very self-centered and narcissistic. Come to think of it, maybe “most” is the wrong description. I find too many people being self-centered already.

    In any case, I think lots of us wonder why someone really loves us, especially early in our relationships. We have some self-doubt, we always want to make a great impression on our dates/partners, avoiding showing them the “crazy” inside of us. I know lots of woman who avoid being seen without makeup. I know men who want to be sure they are showered and clean, avoiding having a date see them at the gym.

    I think it’s natural as you get closer to someone, as you let yourself be vulnerable to have some fear. Hopefully it’s not the maddening inability of immerensis, but just a manageable “I wonder if they’d like the whole me.”

    You should let them in. If they don’t want all of you, they don’t deserve you.

    From the Dictionary of Obscure Sorrows

  • Back in the UK

    I flew overnight and am in the UK this week. It’s a time for me to get into the office and get some facetime with various other Redgaters while I’m over. I usually go a couple of times a year to the office and spend time with co-workers, which I find valuable to build bonds and relationships.

    I was chatting with a friend recently who is remote. Most of his data team is remote, but there is a main office in another city. They are debating Return-To-Office guidelines, and they’ve required any new hires to be in the other city.

    That’s a concern to this person, and others. Should he consider moving or look for a new job? Is there a lack of growth in this position if RTO becomes mandated. In this case, this person would rather have a remote team that gets together once a year.

    Interesting idea, and I’ve seen this in the past when different positions when there were remote teams. It can be expensive, but it can be an investment. I’ll need to think about this and maybe write a piece.

    Not much blogging this week, as it’s been a busy time, so I’ll be back next Monday with a set of more regular posts.