Tag: syndicated

  • Using a GenAI to Help Brent

    Brent had a query exercise recently about train stations moving in some order and having overrides to this order in emergencies. I suppose he’s been traveling a lot lately and ran into an issue.

    In any case, I decided to see if Claude could solve his challenge.

    This is part of a series of experiments with AI systems.

    The Prompt

    I put this into Claude, mostly copy/paste from Brent’s challenge.

    I have a sql table of stations in a physical order. Here is the table and data for stations DROP TABLE IF EXISTS dbo.Stations; CREATE TABLE dbo.Stations     (StationId INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,      StationName VARCHAR(50),      StationPhysicalOrder INT); INSERT INTO dbo.Stations (StationName, StationPhysicalOrder)     SELECT CHAR(64 + n), n     FROM (VALUES         (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),         (12),(13),(14),(15),(16),(17),(18),(19)     ) AS Numbers(n);

    I also have an override table, which contains its own data for emergencies. Here is this code: Transact-SQL 1 2 3 4 5 6 7 8 DROP TABLE IF EXISTS dbo.StationRoutingOverride; CREATE TABLE dbo.StationRoutingOverride     (StationRoutingOverrideId INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,      StationFromName VARCHAR(50),      StationToName VARCHAR(50)); INSERT INTO dbo.StationRoutingOverride (StationFromName, StationToName)     VALUES (‘E’, ‘S’), (‘B’, ‘I’), (‘I’, ‘D’);

    write a query to return a result set that: * Starts with the station with the lowest StationPhysicalOrder * For each row, if there’s a row in StationRoutingOverride to dictate the next step, jump to that station * Otherwise, go to the station with the next StationPhysicalOrder

    The Answer

    Here’s the code:

    WITH StationRouting AS (
         -- Base case: Start with the station having the lowest StationPhysicalOrder
         SELECT 
             s.StationId,
             s.StationName,
             s.StationPhysicalOrder,
             1 as StepNumber
         FROM dbo.Stations s
         WHERE s.StationPhysicalOrder = (SELECT MIN(StationPhysicalOrder) FROM dbo.Stations)
         
         UNION ALL
         
         -- Recursive case: Find the next station
         SELECT 
             next_station.StationId,
             next_station.StationName,
             next_station.StationPhysicalOrder,
             sr.StepNumber + 1
         FROM StationRouting sr
         CROSS APPLY (
             SELECT TOP 1
                 s.StationId,
                 s.StationName,
                 s.StationPhysicalOrder
             FROM dbo.Stations s
             WHERE s.StationName = COALESCE(
                 -- First priority: Check if there's an override for current station
                 (SELECT sro.StationToName 
                  FROM dbo.StationRoutingOverride sro 
                  WHERE sro.StationFromName = sr.StationName),
                 -- Second priority: Next station by physical order
                 (SELECT TOP 1 s2.StationName 
                  FROM dbo.Stations s2 
                  WHERE s2.StationPhysicalOrder > sr.StationPhysicalOrder 
                  ORDER BY s2.StationPhysicalOrder)
             )
         ) next_station
         WHERE next_station.StationName IS NOT NULL
    )
    SELECT 
         StepNumber,
         StationId,
         StationName,
         StationPhysicalOrder
    FROM StationRouting
    ORDER BY StepNumber;

    That doesn’t work, so I added to the prompt:

    2025-06_line0046

    I got a similar error again with the group by in the CTE and pasted that in. The query got rewritten (Again) and this time it ran with this result, which matches Brent’s answer.

    2025-06_line0047

    GenAIs make mistakes, but they can also fix things. I wondered how well this would work, but it worked well. I merely told the model it had made an error and it tried again.

    Imagine if the AI could connect to a db, run its code, and adjust from the error messages itself? The higher end coding tools are supposed to do this.

  • Upgrading SQL Server in a Container

    I decided to update software on my laptop recently during a trip. I’m loathe to do this on most trips, as I don’t want any instability before a presentation. Usually once I hit the airport, I don’t change anything.

    This time I’m visiting a few customers and don’t need to use my computer. I’ll be taking notes on paper, and while working in the hotel, I decided to upgrade Rancher Desktop after a notification, as well as SSMS, VS, and a few other pieces of software. I decided to patch my SQL Servers as well, which was easy. This post shows how.

    Update: the original screenshot below was the wrong one. That has been updated.

    Upgrading SQL

    I don’t have SQL Server installed on my laptop. Instead, I have a few container instances running under Rancher Desktop. Each of these has a docker compose file and a batch file to start and stop the containers. I’ve written about this before, but I didn’t cover upgrades.

    Here is the upgrade process. First, I find the docker compose file, which is in c:\data\xxx where xxx is the instance. Here is the file for my SQL 2019 instance.

    2025-06_line0015

    I open this in VS Code, and it looks like this.

    2025-06_line0016

    I next check the build list for 2019 on SQL Server Central. It shows me that CU32 is the latest, which means I haven’t patched this in some time. I also haven’t used this instance much. I need to change this.

    Here’s the change: in the file, I update line 5 to say 32 instead of 27.

    2025-06_line0017

    I save this and then double click the batch file to start my 2019 instance. When I do that, I see the new image being pulled down.

    2025-06_line0018

    Once this completes, the container starts and I can connect. When I do that, I see this:

    Upgrade complete.

    Now to edit the other docker files.

  • Monday Monitor Tips: Searching Permission Changes

    During a demo of Redgate Monitor Enterprise to a customer, they asked about how to search for permission changes. This post examines how you can do that in Redgate Monitor.

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

    Permission Changes

    Redgate Monitor Enterprise adds a few security features to the tool that track things that organizations can struggle to track as their estates grow. There is a security menu item at the top of your Redgate Monitor web page. You can see this expanded on our demo system at monitor.red-gate.com.

    2025-06_0095

    Click the permission entry and you will see this starts on a page that is titled Permissions. There are a few tabs below the title (Permission changes, Servers, Databases, Users). We start on Permission changes, which helps us to see the various changes that have occurred.

    2025-06_0096

    Below this, we see a date box that is set for the last week, along with a few other items. By default we show you the last week’s worth of changes and all the data. However, you can easily alter this.

    2025-06_0097

    This can be a lot of data, especially in an enterprise, so perhaps I only want to see certain things. I can click “Columns and choose which data I care about. Here, I’ll uncheck a few boxes.

    2025-06_0098

    Notice this has rolled up some changes, so I don’t see quite as much as data as I do in the default view. This is useful when I want to see the “who had a change” and not every detail.

    2025-06_0099

    I can, of course, change the date range. We give you some quick defaults, or you can use the calendar picker to choose a range.

    2025-06_0100

    When I do this, I only see some changes, those that apply to that date range.

    2025-06_0101

    If I want to further filter things, I can choose that item. You can see the various items below I can choose from.

    2025-06_0102

    Let’s set  this to “Changed by” the sa account. When I do that, notice the “Filters” icon is annotated saying I have 1 filter condition. I also only see the one row changed by SA.

    2025-06_0104

    I will expand my date range and remove the filter while adding all the columns, and I see this data:

    2025-06_0107

    That’s a lot, but I can change the density. Here are the choices.

    2025-06_0106

    Here is compact. Now all 10 rows fit on the page:

    2025-06_0108

    Comfortable only shows 7 rows (9 in standard).

    2025-06_0109

    Lastly, I can set the number of rows on the page in the lower right.

    2025-06_0110

    Summary

    Security is becoming something more people need to report on, especially public companies or those regulated. This feature of Redgate Monitor helps you satisfy auditor requests with the information they need to verify you are watching your systems.

    Or, at least that you know Redgate Monitor is doing so.

    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.

  • SQL Bits 2025 Wrap

    SQL Bits 2025 was amazing, as always. It’s been my favorite conference to attend, with lots of friends, a family atmosphere, and some amazing speakers from whom I learn many things.

    This year I wasn’t picked as a speaker, which is fine. Their committee didn’t like my submissions for some reason, which happens. I’m disappointed, but that’s it. I am fine with any event who chooses me or choose not to have me. However, since Grant and Kellyn were accepted, I planned a trip to Cambridge for the following week. A month or so ago, Redgate asked me to just attend and be a part of the booth. I agreed, and extended my trip lightly to arrive Friday.

    My hotel was just past the Excel center, so as I walked from the train, I stopped by Friday afternoon. Things were relatively quiet, and the neon sign wasn’t lit, but I went in and saw a number of friends.

    2025-06_line0064

    I saw a few Redgaters as well, and loved the branding (though not the colors) on the bean bags this year.

    2025-06_line0065

    Friday was a bit of a hangout for a few hours, but I had to get to the hotel to get some work done, including a few late night customer calls from the US.

    Saturday was more fun. I spent most of the day at the Redgate booth, which had a great whack-a-mole game where two people could compete.

    2025-06_line0066

    I didn’t attempt it, but I saw quite a few people giving it their all. There was a magnetic leaderboard to the side, with the counts climbing and climbing throughout the day. Event the Redgaters had fun.

    2025-06_line0076

    Lots of selfies with friends, including quite a few North Americans that I relish the time to catch up with as I don’t often see them in the States.

    2025-06_line0070

    2025-06_line0069

    2025-06_line0068

    2025-06_line0067

    I got recruited (again) by Daniel, who keeps trying to get me to Stockholm for his Data Saturday event. He spent some time showing me pictures of his amazing speaker dinner on an island in the area, so I might have to try and make time in my schedule for 2026 to get over there.

    2025-06_line0075

    The event was plenty busy, with lots of time between sessions to wander the expo hall, meet friends, chat with vendors, and just relax.

    2025-06_line0073

    I’m sure you’ll see lots more pictures, as Mikey was busy taking lots of pictures. I’m sure he got more than his 10,000 steps each day, trying to take as many shots as possible. I managed to grab one of him during a session.

    2025-06_line0072

    I made a few new friends, getting the chance to chat with people that knew me from SQL Server Central or just had a question. A few selfies, one of which was with this cool hat in keeping with the neon theme.

    2025-06_line0074

    Redgate had a great neon sign, which was more red in person, and I’m looking forward to seeing this in the office at some point.

    2025-06_line0077

    Events always end too soon, though I’m usually worn out and ready to move on from early mornings and late nights. I am glad I got to hit the Pelaton each day, though my body was tired and I struggled a bit with late night conversations both days.

    I was honored after a quiet dinner Saturday to sit with the organizers for a drink after they had their post-event dinner. They are great friends I’ve known for many years and I’m proud of what they’ve built. Reminiscing about different highs and lows across the various events in different cities was a memory I’ll cherish.

    It was especially memorable as Alex Whittles is stepping away to focus on Purple Frog Systems after ten years. It’s bittersweet, but I certainly understand volunteer efforts are a time and place thing, and people come and go as their lives change. I wish him well and I’m sure we’ll continue to see him as a speaker, likely with a little more energy as he won’t need to be dealing with the logistics of running the event at the same time.

    An amazing few days, and I hope I have the chance to come back next year.