Tag: syndicated

  • Speaking at SQL Saturday Denver 2024

    It’s just a couple of days away from SQL Saturday Denver 2024. This Saturday, come join me at the Lowry Convention Center in Aurora for some great talks. We are lucky in the Denver area that we have quite a few great speakers and talented data professionals, so check out the schedule.

    Then register and come.

    Come learn about SQL Server, about PostgreSQL, Snowflake, Powershell, and more. I’m looking forward to sitting in a few sessions, and I have a few of my own. I’ll be delivering these talks:

    • Best Practices for Seamless Database Deployments
    • Architecting Zero Downtime Deployments

    I hope to see you there.

  • Expanding Northwind with Prompt+

    I was trying to do a little testing of our subsetter and needed a larger database. So I decided to ask Prompt + to help me with a little AI assist. This post looks at what happened.

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

    Getting More Data

    I had a Northwind_FullRestore from my experiments with Alex Yate’s quick PoC tool. I selected that database and asked for a little code. I asked the AI to give me 1000 more rows of data in the Customers table. I got this code.

    -- This script inserts 1000 rows data entry into the dbo.Customers table
    WITH numbers
    AS ( SELECT TOP (1000)
                 ROW_NUMBER () OVER (ORDER BY
                                       (SELECT NULL)) AS num
          FROM sys.all_objects)
    --INSERT INTO dbo.Customers
    --  (CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)
    SELECT
       'CUST' + RIGHT('0000' + CAST (num AS nchar(4)), 5)
    , 'Customer' + CAST (num AS nvarchar)
    , 'Contact' + CAST (num AS nvarchar)
    , 'Title' + CAST (num AS nvarchar)
    , 'Address' + CAST (num AS nvarchar)
    , 'City' + CAST (num AS nvarchar)
    , 'Region' + CAST (num AS nvarchar)
    , 'PostalCode' + CAST (num AS nvarchar)
    , 'Country' + CAST (num AS nvarchar)
    , 'Phone' + CAST (num AS nvarchar)
    , 'Fax' + CAST (num AS nvarchar)
    FROM numbers;

    Then I decided to go big. I changed my prompt, as you see below, and got more data. My new prompt: expand this to add 10GB of data to this table

    I got this code:

    -- This script adds approximately 10GB of data to the dbo.Customers table
    -- Firstly, we need to calculate the approximate size of each row. 
    -- For simplicity, we'll assume each row is ~1KB in size after considering nvarchar data expansion.
    -- Therefore, to add 10GB of data, we need approximately 10,000,000 rows.
    WITH numbers
    AS ( SELECT TOP (10000) -- This will generate 10,000 rows in the CTE
                 ROW_NUMBER () OVER (ORDER BY
                                       (SELECT NULL)) AS num
          FROM
            sys.all_objects a
          , sys.all_objects b)
    INSERT INTO dbo.Customers
       (CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax)
    SELECT
       'CUST' + RIGHT('00000000' + CAST (numbers.num + seqnum AS nvarchar), 8) -- 8 character CustomerID to accommodate large number of rows
    , 'Customer' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Contact' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Title' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Address' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'City' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Region' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'PostalCode' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Country' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Phone' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    , 'Fax' + CAST (numbers.num AS nvarchar) + CAST (seqnum AS nvarchar)
    FROM
       numbers
       CROSS JOIN
         ( SELECT TOP (1000)
                  ROW_NUMBER () OVER (ORDER BY
                                        (SELECT NULL)) AS seqnum
           FROM sys.all_objects) seq;

    The Results

    The results were a bit underwhelming. I ran it and got this:

    8-2-2024-0005

    The problem here is that the CustomerID is a 5 character field. The comment in the code notes that this is now an 8 character field, but that’s not great as I might not want to change the size of the field.

    I then asked this: change this script to ensure the customerID is less than 5 characters and alphanumeric

    I got the same script, but the first line of the select was:

    'CUST' + RIGHT('00000000' + CAST (numbers.num + seqnum AS nvarchar), 8) 
    -- 8 character CustomerID to accommodate large number of rows

    Now when I run it, I get a problem with postal code, which now has the truncation error.

    My Thoughts

    It’s easy to say this was a failed experiment. I didn’t get working code. But I got a bunch of code that was close to what I need, in a fraction of the time that it would take me to write this, even with SQL Prompt. Then add in the fact that I can edit this code to what I need, which works, and saves me times.

    I think this has potential for shortcutting some work and getting me closer to what I need quickly, even if it’s not perfect. If I’d have asked a junior dev to help me with this, I might still have to edit their code. Just as I do with my AI assistant.

  • T-SQL Tuesday #177–Keeping track of database code


    This month’s invitation is from Mala Mahadevan, who has hosted 5 times. This latest one is one that is near and dear to my heart as I use source control most days and I think it’s important for database code.

    I’ll explain why below, but I’m glad to see this as a topic. We have a wide variety of technical topics being proposed, but not a lot about software engineering as a discipline, which is part of what version control is. Not building features, but better managing your process.

    If you want to host a T-SQL Tuesday, ping me.

    Capturing Database Code

    There are many ways to capture code, but I work for Redgate Software, so I use Flyway. Since I work there, I get a paid version, but I work with customers all the time and see a variety of things. If I didn’t have Redgate tools, I’d likely use something like SQL Compare to capture off database code, since that’s easy. Or SMO through SSMS.

    As for how I work with code, I use Git to store the code. Git is ubiquitous and I rarely find customers without Git. Sometimes the data teams aren’t using it or don’t know how, but that’s why I’ve written some Git articles on getting started.

    I also try to work in branches, with a protected main branch. This means no one can commit code to main, but rather need to commit it elsewhere and use a PR (pull request) to move the code into main. I do this with a lot of customers, helping them understand how to use version control to manage their code.

    For my git work, I primarily work in GitHub in public repos. I’m at https://github.com/way0utwest, where I keep a lot of sample projects for things I work on with customers to demonstrate how to use Redgate tools, or just manage code better.

    There are lots of ways to capture code, format it, and deploy it. However, you should use git and learn to manage your code within a team. I’d also suggest you use Flyway to deploy the code. There is an OSS version, and because it supports many platforms, if your company adopts PostgreSQL or DataBricks, you can still use a similar process to deploy code. Learn it and use it.

    But first, get code into a Git repo.

  • Grouping by Object Type in SQL Compare

    A customer recently was asking about grouping objects by type to see all the differences in two databases for one set of objects, like all stored procedures. This post shows how this works and what this changes for your system.

    This is part of a series of posts on SQL Compare.

    I have two databases, Compare_1_Source and Compare_2_Destination. I made a number of changes to the Source db and when I run SQL Compare between these, my default view shows me the different objects, as well as those in one database and not in the other. You can see this below.

    Screenshot 2024-07-31 170641

    This is the way most of us want to make changes, by deciding from this short list what changes to deploy. If you look closely, you can see there are 115 objects that are identical, so it’s nice to be able to see what has changed.

    However, I have had a few people ask to see all the stored procs that have changed, so they can decide what needs to move. They aren’t ready for table changes.

    In the upper right corner, above the destination database, I have a drop down for grouping options. I can use the default (type of difference), switch to type of object, or have no grouping.

    Screenshot 2024-07-31 171350

    If I choose object, I see this grouping. In here, the stored procedures are expanded, showing my differences. Second, in the middle, near where the checkboxes are for object selection, I see a count of how many objects are selected, and how many are changes. However, I don’t know the type of change.

    Screenshot 2024-07-31 171501

    I’ll modify a procedure and delete one and I see something slightly different. Now I see the object name to the right side of the checkbox, so I can infer a change if the name is on both sides, or a delete if there is an “x” next to the name.

    Screenshot 2024-07-31 172047

    My default view of tables is shown below. Note that my table changes are mixed within non-changed tables.

    Screenshot 2024-07-31 171517

    However, I can click on the Last modified column and resort the data. If I sort descending, then I see my table changes at the top.

    Screenshot 2024-07-31 172416

    Toggling these settings allows me to see different views. If I just want changes without groups or differences, then I can set no groups and see this (I’ve sorted by modified date).

    Screenshot 2024-07-31 172450

    I have a request to hide the unchanged objects, but that’s not something we do now, nor am I sure we will change things. You can submit your own ideas on Uservoice and get some votes from friends.

    SQL Compare is an amazing tool that millions of users have enjoyed for 25 years. If you’ve never tried it, give it an eval today and see what you think.