Tag: Redgate

  • 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.

  • Virtual Data

    Yesterday I republished an editorial from 2014 for the holiday. The topic was production subsets of data, which has been something that many data professionals have struggled with for years. Many of us have built scripts to delete, change, obfuscate, or alter production restores as a way of providing useful, but manageable development database sets. Or maybe it’s just some of us. I’m sure more than a few of us have given up on this task and just restored production databases in entirety to test and development systems.

    I changed over my career to become a fan of additively building a known dataset rather than deleting extra data. I advocate adding rows from production (properly masked/obfuscated) and maintaining this set over time as requirements change. However, this isn’t without it’s own administrative headaches. I think it’s easier, but this does require commitment from everyone to keep going over time. It’s certainly better than each developer adding their own 10 rows of data to a table for testing.

    A year ago, Redgate released SQL Clone, designed to solve some of these issues. Once an image is created, new databases for test and development and be provisioned in seconds. I found this to be an amazing product that really changes how I develop against databases, though it does require me to stop getting caught up trying to undo changes or manage a single database. Instead, I need to ensure I am saving code to version control and then build the habit to drop and rebuild a baseline database.

    As we’ve worked on SQL Clone, I’ve found that there are lots of companies that offer similar ways of virtualizing your data, giving you access to large, production scale systems in seconds. Data masking, obfuscation, and more are features, with some vendors requiring specific hardware. Others, like Red Gate, have software add-ons (Data Masker).  All of these products cost money, which can be an issue for many organizations, but I’m glad that this technology is growing and advancing. With GDPR and other draft legislation, many of us need to take better care of our data and build more secure architectures.

    Containers are another interesting way to virtualiza data, though they don’t solve the scale issues. If you can work with a smaller data set, and maintain that, then containers might provide a fantastic way for you to learn to build, teardown, and rebuild databases in seconds.

    The world of databases hasn’t changed a lot in some ways across my career, but in others, I’m amazed. Data virtualization is one of these areas, and if you haven’t trialed the technology, maybe you should give it a whirl this year.

    Steve Jones

    The Voice of the DBA Podcast

    Listen to the MP3 Audio ( 3.6MB) podcast or subscribe to the feed at iTunes and Libsyn.

  • Join me for Masking, Privacy, Protection, and Clones at SQL in the City Feb 28

    Registration is open for SQL in the City 2018. Our first event is Feb 28 and I’ll be heading back to the UK for the event. This time Grant and Kathi will be there and we’ll be joined by the amazing Ike Ellis. This is an event to watch.

    I’ll be covering some GDPR stuff about compliance, with good information that all DBAs and system administrators should know. This is a prove you’re doing what you have decided to do session.

    In the afternoon I’ll also cover some enhancements to SQL Clone in our Privacy bundle that helps you mask data from production and build your dev/test environments in a way that can protect your sensitive data.

    Some Redgate products will be used to show how to accomplish the same tasks, but all of us will be talking about core concepts and ideas that you need to know. We’d like you to consider our software if it provides you with value for the cost, but either way, you will learn about things that we all think are important.

    Register today and I’ll see you in a few weeks.

  • Moving Lookup Data with ReadyRoll

    I’ve been using ReadyRoll for a small project and wanted to move some lookup data. There are some tables where I want to keep data in sync across environments, so if my build and release pipeline can do this, great. ReadyRoll makes this easy, and this is a short post to show how.

    The Current Environment

    I’ve got a table in my dev database that has SQL Server versions. I can see the list here:

    2018-01-31 12_15_05-SQLQuery6.sql - (LocalDB)_Projectsv13.SSBuilds_1Dev (PLATO_Steve (51))_ - Micros

    In my QA and staging systems, I see this (only one is shown, but it’s the same in both).

    2018-01-31 12_13_41-SQLQuery5.sql - dkranchstaging.database.windows.net.ssbuildsRRstaging (vstsdeplo

    The goal is to have this data migrate with other changes in a build and release pipeline.

    Adding Data to the Project

    I’ve already built this as a ReadyRoll project and set up a build and release pipeline in VSTS. Now I want to include my data.

    In the ReadyRoll tool window, I have refreshed the project and I see everything in sync. That’s good, and that’s how I want to be starting a small section of development.

    2018-01-31 12_11_09-builds_azure - Microsoft Visual Studio

    I want to find my table, so I need to expand the “Identical Objects”. When I do that, I see a list of all objects in the database.

    2018-01-31 12_17_22-builds_azure - Microsoft Visual Studio

    I can scroll down to find my table. When I do, I’ll right click it to get a few options. One of these is “Include Table Data”. We want to pick this one.

    2018-01-31 12_20_01-

    Once I do that, I get a note to refresh again. This is so RR can determine what table data needs to be added to a migration script.

    2018-01-31 12_21_07-builds_azure - Microsoft Visual Studio

    My changes show that I need to get 11 rows of data into a new script.

    2018-01-31 12_21_44-builds_azure - Microsoft Visual Studio

    I click Import and generate script, which will build my migration script and add it to the project. In my case, this is script 4.

    2018-01-31 12_23_00-builds_azure - Microsoft Visual Studio

    Note that this script has a few things in it, based on a call to SQL Data Compare in the background. First, it sets a dateformat. Next, it does the insert for an empty table, since that is the situation I’m in. Last, this uses the SET IDENTITY_INSERT option.

    If you don’t like these options, change them here. You can alter this script to suit your environment. Remove the IF, let the identities be what they are, make the changes that matter to you.

    The only thing I’ll do is click the script name twice to edit it.

    2018-01-31 12_25_08-builds_azure - Microsoft Visual Studio

    The numeric sequencing is important. The rest, not so much. I’ll choose something simple here.

    2018-01-31 12_25_21-builds_azure - Microsoft Visual Studio

    Build the Project

    I can build locally, and I always should to be sure things work. Once I see this and I’ve tested a few things, I’ll let the “system” do more work.

    2018-01-31 12_28_32-builds_azure - Microsoft Visual Studio

    The nice thing about ReadyRoll is that I can include my database project alongside application projects, if I want. For application developers or hybrid developers, I can use a consistent interface for saving changes to version control.

    In Team Explorer, I’ll check changes, add a comment, and then Commit and Push.

    2018-01-31 12_30_36-builds_azure - Microsoft Visual Studio

    If I go to VSTS, I’ll see the build in progress. I’m using a local build agent and usually within 15 seconds, my build will start. Sometimes it’s really fast.

    2018-01-31 12_31_04-builds_azure-CI summary

    If I click the build number, I can see I’ve barely caught this before it finished.

    2018-01-31 12_31_19-Build 36

    The build completes, so now I need to check releases. I have a CD trigger that will deploy to a local QA instance when the build succeeds. If I go look at the release, I’ll see that’s occurred.

    2018-01-31 12_35_49-Release-14 - Visual Studio Team Services

    This worked, so let’s check the QA instance. As you can see, my data was deployed.

    2018-01-31 12_36_43-SQLQuery7.sql - (local)_SQL2016.ssbuilds_rr_sjones_2_integration (PLATO_Steve (7

    If you were watching closely, you see I have a small data issue. I need to correct that, but that’s for another post.

    ReadyRoll is a part of the SQL Toolbelt, and if you’re a customer, I’d urge you to start a PoC and see what you think of the tool. ReadyRoll Core, with limited features, is included with Visual Studio Enterprise, and if you’re a customer of Microsoft, you can try that. We also have 14 day trials if you’d like to do this on your own.