Category: Blog

  • Data Masker for SQL Server–Syncing Values Across Rows

    I’ve been playing with Data Masker for SQL Server v6 and it’s an interesting product. I like the way it works, but I do find it a little challenging sometimes to figure out how to mask values. I’ve written a set of posts for different scenarios.

    We had a customer ask about how to mask data across rows. The customer had some data in a table that was a standalone table, and contained data in a column that matched across rows. They wanted this changed, but the matching between rows kept.

    In other words, here’s a small mocked set of the original data:

    myid        Mychar     myint       mytinyint
    ----------- ---------- ----------- ---------
    1           Steve      12345       1
    1           Steve      12345       2
    2           Andy       12345       3
    2           Andy       12345       4
    3           Brian      12345       5
    3           Brian      12345       6
    3           Brian      12345       7

    Here are the results they want:

    myid        Mychar     myint       mytinyint
    ----------- ---------- ----------- ---------
    1           aaa      12345       1
    1           aaa      12345       2
    2           bbb       12345       3
    2           bbbb       12345       4
    3           ccc      12345       5
    3           ccc      12345       6
    3           ccc      12345       7

    I thought this was an interesting scenario, so how do we mask this? It’s not that hard, so let me show you this.

    First, let’s create a new masking set. I won’t walk through that here, but once you have a set connected to your database, here’s what we do.

    First, we need to substitute data out. In this case, I’ll substitute the name only. In a real world, we’d probably need to substitute the myid and myint columns as well, but I’ll leave those again.

    I add a new Substitution rule first.

    2018-03-02 15_22_05-Edit Substitution Rule

    This is a standard rule. I’ll add my column and pick a dataset. In this case, I’ll just pick make first names (Names, First, Male) and use that. This will result in a random set of names. I’ve chosen unique values. This is important as across a large number of rows, I could end up with random values that match, but with different MyID values. That would be bad.

    If I save and run this rule, I’ll see something like this.

    2018-03-02 15_25_04-SQLQuery1.sql - DKRSPECTRE_SQL2016.sandbox (DKRSPECTRE_way0u (52))_ - Microsoft

    Not quite what I need, but it’s a start. The important thing is that the first myid=1 is different from the first myid = 2, which is different from myid=3.

    Next we’ll add a Table Internal Sync rule. This is the rule that fixes values across rows inside a table. Here’s the basic config. Note that I choose a table and then I choose the columns that need syncing, in this case just the mychar column.

    2018-03-02 15_27_22-Edit Table-Internal Rule

    I need a way to determine which sets of rows should match. In this case, the myid column is used for that. If you examine the initial set, I have the same values for each name. This is what groups things together, so I’ll use this.

    One Note: The red “I” to the right means this isn’t an indexed column. If I wanted better performance, I can add an index for this column, either permanently or just for the masking process.

    Now I execute this rule, and I see these results:

    2018-03-02 15_31_18-SQLQuery1.sql - DKRSPECTRE_SQL2016.sandbox (DKRSPECTRE_way0u (52))_ - Microsoft

    I have my groups back.

    I could expand this to include other columns as well, substituting the myint column in my first rule and including it in the second.

    Setup Scripts

    Here is the code to set this up:

    CREATE TABLE MyTestMask
    ( myid INT
    , Mychar VARCHAR(10)
    , myint INT
    , mytinyint TINYINT PRIMARY KEY
    )
    GO
    INSERT dbo.MyTestMask ( myid,
        Mychar,
        myint,
        mytinyint
    )
    VALUES
      ( 1, 'Steve', 12345, 1)
    , ( 1, 'Steve', 12345, 2)
    , ( 2, 'Andy', 12345, 3)
    , ( 2, 'Andy', 12345, 4)
    , ( 3, 'Brian', 12345, 5)
    , ( 3, 'Brian', 12345, 6)
    , ( 3, 'Brian', 12345, 7)
    GO

    I’d urge you to give Data Masker a try if you’re looking to ensure compliant, safe data sets for your non-production environments.

    I have other articles on Data Masker if you’re interested.

  • SQL in the City is Live

    You can watch on YouTube now: https://www.youtube.com/watch?v=0qyMutBkZsg

    If you want slides and notifications, register on the Redgate hub.

    We’re recording the sessions and they’ll be available whenever you have time to watch, but join us today. We’re live.

    The keynote is done, with more sessions to come today.

  • Typing Alternative Characters

    I tend to work in the US English world. I’m somewhat embarrassed to note that I really only know one language and most of my work has been with US centric industries. I’ve rarely had the need to deal with Unicode and most of my databases have used varchar() everywhere. However, I know a little about nvarchar and am trying to be better about becoming familiar with using these structures.

    Recently I was working on a piece and needed to type a £ character. If I were on one of the Redgate demo systems, that would be no problem. There’s a key for this character. However, I’m a US centric guy on a US system.

    I could have cut and pasted the character, but I was wondering if there was a way to type it. There is.

    You can use ALT codes to type the Unicode character. In this case, it’s 0163, so you can hold down the ALT key and then type  ‘0163’. Doing that gets you £.

    Pretty cool.

  • Off to SQL in the City 2018

    I’m off today on a plane, flying to the UK for this Wednesday’s SQL in the City broadcast. This is our first event of 2018, and I’m excited. We’ll be talking GDPR and security, not the most exciting of topics, but we also have some cool new products to show off. I’m excited to see what people think of the work that our development teams have been doing.

    I’m also doing the keynote, which is both a little exciting and scary. Usually Simon Galbraith, founder and CEO does these, but for some reason I’ve been picked this time. I hope you enjoy what I have to say, and hopefully I don’t mess things up.

    I’ll also be showing you some improvements to SQL Clone with integrated data masking. This is a very well thought out product, which will really help many of you prepare databases for development and test without exposing sensitive data.

    Register today and I’ll see you, or rather, you’ll see me on Wednesday.