Category: Blog

  • The Book of Redgate–Being Reasonable

    As a part of the Book of Redgate, we have a series of (red, of course) pages with the title “What we believe”. These are our values, as set up by the founders. The first one of these is:

    You will be reasonable with us

    We will be reasonable with you

    Two simple sentences, but they really encapsulate how we try to work together. We know there are stressful times, there are hard times, and while we all want to follow the golden rule (treat others as you would want to be treated), we sometimes fail. However, we try to be reasonable with each other.

    If I ask for something, others should try to accommodate me. If I ask for too much, and they tell me that, I should try understand that. Being reasonable is having sound judgment, being fair and sensible, not being extreme.

    We try to get along with others. Some good examples of this are us setting normal working hours, but being willing to flex with others. If someone goes above and beyond, we recognize that and perhaps go out of our way to make it up to them.

    One example of this stands out in my mind. At our annual company meeting our CEO told a story of a deal that they were trying to close during the year. A crucial part of this deal was one employee, who had scheduled a holiday previously. As the deal was getting close, and in danger of problems, this employee came off vacation to help finish something. Our CEO not only recognized this, but personally thanked them in front of the company, gave them more holiday to make up for it and sent a gift.

    We are reasonable with each other, all of us being willing to bend and flex, but not abusing that willingness.

    Just like a family does with each other. At least, my family does.

    I have a copy of the Book of Redgate from 2010. This was a book we produced internally about the company after 10 years in existence. At that time, I’d been there for about 3 years, and it was interesting to learn a some things about the company. This series of posts looks back at the Book of Redgate 15 years later.

  • Comparing My Current Schema with a Backup with SQL Compare

    A customer asked if they needed to restore a database from backup to compare the schema in a database. They don’t and this post shows that.

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

    Setting Up a Comparison

    When I open SQL Compare, I see a screen that looks like what I’ve shown below, with a database to database comparison.

    2025-03_0096

    At the top, to the left of “Source”, there is a drop down arrow. If I pick that I see these choices: database, backup, snapshow, scripts folder, SQL Source Control, SQL Change Automation, Flyway. Those last 3 are project types for Redgate tools.

    2025-03_0097

    If I select backup, I get a dialog where I can add my backup set files. I can add full or diff backup files, but not transaction log files. If I click the “+Add backup set flies”, I get a file picked, and I can find a backup file.

    2025-03_0099

    Once I pick one, I see it in my list. I can now clear the list or add more files. The details of how this work are documented at: https://documentation.red-gate.com/sc/working-with-other-data-sources/working-with-backups

    2025-03_0100

    Once I have my backup, I’ll set the target, in this case a copy of Northwind that I’ve altered and called Westwind. This is on my local instance.

    2025-03_0101

    When the comparison completes, I see the differences. This was without any sort of restore on my instance. Note that the top left icon for Northwind_FullRestore has a different icon. I have this database on this instance, but it’s different than the backup.

    2025-03_0102

    If I expand the results, these look like any comparison. I see those things that are the same, only in one or different. In this case, as we are trying to make the target look like the source, those objects in my db and not in my backup would be dropped if I deployed all changes.

    2025-03_0103

    Summary

    This is a short demo of using a backup as a comparison source against a database. I haven’t really shown a flow or scenario, but I’ll do that in another post. This is just a short proof that this works.

    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.

  • A New Word: Zverism

    zverism – n.  the wish that people could suspend their civility and indulge in the physical side of each other first, sniffing each other’s hair like dogs, staring unabashedly at interesting faces, reveling in a beautiful voice like a song on the radio.

    No zverism. Not for me, and not for anyone. Too many people are poorly behaved, and (especially men) would act creepy.

    I could accept zverism for voices, but nowhere else.

    From the Dictionary of Obscure Sorrows

  • CHOOSE’ing a Beer: #SQLNewBlogger

    We recently published an article on CHOOSE at SQL Server Central. I thought it was a good intro, but as someone noted in the comments, how do you use CHOOSE? Do you have to hard code choices?

    This post shows you don’t.

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

    A Scenario

    I have a table that contains some data. In this case, about beer. I like beer, and this was a fun little demo. I’m not recreating the DDL because, well, you might like different beers.

    2025-03_0145

    In any case, this is simple to set up.

    If I wanted to choose some data from this table based on an index, I could do something like this. This code populates the first index in choose with beers and the second with brewers. CHOOSE is 1-based indexing.

    DECLARE @i INT = 1;
    SELECT
       CHOOSE (@i, beername, brewer)
    FROM dbo.Beer AS b2;

    This returns me the beers.

    2025-03_0146

    If I changed the value to 2, I get brewers. I show both below.

    2025-03_0147

    How would I use this? Maybe a user is asking to edit either a home or shipping address. I can index these by returning the column data as index 1 or 2, and linking the user suggestion to the index. They choose home, we pass in 1. If we qualify the query with a WHERE clause to one customer, they get just their data to edit.

    I could even do something silly, like getting values from different places. For example, here I’ll use string_split on a value.

    DECLARE @i INT = 2;
    DECLARE @s VARCHAR(20) = 'Vodka,Tequila,Bourbon'
    
    ; WITH a (value)
    AS
    (SELECT a.value FROM STRING_SPLIT(@s, ',', 1) AS a
      WHERE a.ordinal = 1
    ),
      b (value)
    AS
    (SELECT a.value FROM STRING_SPLIT(@s, ',', 1) AS a
      WHERE a.ordinal = 2
    ),
      c (value)
    AS
    (SELECT a.value FROM STRING_SPLIT(@s, ',', 1) AS a
      WHERE a.ordinal = 3
    ) 
    SELECT
       CHOOSE (@i, a.value, b.value, c.value)
      FROM a, b, c

    This is silly, but it does return an acceptable answer.

    2025-03_0148

    I don’t know that there are many places that I’d use CHOOSE, but as I play with it, I can see that it could be a handy tool at times with a little creativity.

    SQL New Blogger

    This post took me about 15 minutes to write after I saw a comment. I set up a scenario and posted a reply, then took that code to structure this post. The STRING_SPLIT piece was the longest, as I had to futz with code, but I show some use of a new feature and how I might incorporate this into an application.

    You could write your own creative blog on this, probably in 30 minutes or less. I bet you’d get asked about this in an interview as it’s kind of funny.