Tag: Redgate

  • Custom Placeholders in SQL Prompt 7

    I work for Redgate and write about products. I’ve got a series of SQL Prompt posts here on little things I like. SQL Prompt might be my favorite tool.  SQL Prompt will be yours as well if you give it a try.

    I love my snippets in SQL Prompt. Adding some snippets can make work go so much quicker.  I add new ones all the time, based on the tasks I’m doing and I find that code can almost write itself.

    SQL Prompt 7 was just released, and it added a neat feature to the suggestions that I really appreciated. You can now add your own placeholders for code.  How does this work? Let me show you.

    Let’s imagine that I want to quickly view a table and update a column. I build a snippet like this:

    2015-09-09 15_01_15-SQL Prompt - Edit Snippet

    Notice that I’ve added “tblnm” as a placeholder inside of two dollar signs. This is my custom value. It’s not a parameter, but rather a placeholder.

    I can set a default value if I’d like.

    2015-09-09 15_01_10-SQL Prompt - Edit Snippet

    Now when I start typing, I see my snippet appear.

    2015-09-09 15_01_24-ObjectDefinitionBox

    I hit tab and then I get my snippet. The cursor is where I specified with the $CURSOR$ placeholder that was built in. However my custom placeholder has a list of the objects available that fit here.

    2015-09-09 15_01_32-SQLQuery1.sql - aristotle.sandbox (ARISTOTLE_Steve (67))_ - Microsoft SQL Server

    If I select one, I get my code. Note that the default value was inserted above.

    2015-09-09 15_01_45-SQLQuery1.sql - aristotle.sandbox (ARISTOTLE_Steve (67))_ - Microsoft SQL Server

    Very cool.

    Now I can adjust my snippets with my own placeholder that makes sense to me, and have intellisense pop up right away.

    Another keystroke or two saved.

  • Custom Column in SQL Data Generator

    This is a series on SQL Data Generator, covering some interesting scenarios I’ve run into. If you’ve never tried it, SQL Data Generator is a part of the SQL Toolbelt. Give it a try today with an evaluation today.

    One of the interesting things with Redgate’s SQL Data Generator (SDG) is that it allows the user of custom data patterns for your columns. The user of regular expressions (RegEx) is used, which is something I find many SQL Server DBAs don’t really work with often.

    While there are plenty of RegEx tutorials out there, I wanted to give some simple ideas here that I’ve used to make slightly more realistic data.

    Help

    There’s a help icon available if you choose a column in one of your tables and have a regular expression selected. In this case, I can see there are a few different suggestions for the “title” column.

    2015-08-28 09_30_34-

    SDG guesses that title is a Mr/Mrs/Ms field, but it’s not. I really need something that looks like the title of an article. If I scan through some of the articles on SQLServerCentral, I see titles like:

    In this case, there are a few patterns. SQL Server appears in a few places, Some articles user a “top x” type of format. The word lengths vary, and are in the 6-12 range. Around six or so words are in many titles.

    Building a Regular Expression

    I could certainly do something like this, which just gives me a few words made up of random letters, of the specified lengths.

    [A-Z]{3} [A-Z]{5} [A-Z]{7} [A-Z]{4}

    I’ve got a 3 letter word, then a 5 letter one, then 7, then 4. All upper case, all random. That gives me results like this:

    2015-08-28 09_38_37-SQL Data Generator - TestSDG.sqlgen _

    Not quite what I want. I’d rather have some words at the beginning like “A”, “The”, or “Top”. I can do that with literals.I enclose those in parenthesis rather then brackets.

    (A|The|Top) [A-Z]{5} [A-Z]{7} [A-Z]{4}

    This gives me something slightly better.

    2015-08-28 09_41_23-Get Started

    Not perfect, but better. Let’s clean up the words themselves, following some capitalization rules for titles. In this case, we’ll use a pattern like this:

    [A-Z]{1}[a-z]{5}

    Now I see something a bit better. This doesn’t make complete sense, but it does look like random word structures.

    2015-08-28 09_43_20-SQL Data Generator - TestSDG.sqlgen _

    Let’s change the “Top” item to include a number. I can do that, but changing just the part of the OR (|) that includes Top. I’ll do that like this:

    (A|The|Top [3-7]{1})

    Now I see a number, randomly from 3 to 7, when Top comes up.

    2015-08-28 09_46_20-SQL Data Generator - TestSDG.sqlgen _

    This still isn’t great. How about if I include SQL Server at the end? I’ll use a space, or something with SQL Server.

    ( |(in|for|on) SQL Server)

    That shows me a random addition to SQL Server a the end of some titles.

    2015-08-28 09_48_31-SQL Data Generator - TestSDG.sqlgen _

    Getting better. I can even use the space or something to get the versions of SQL Server.

    ( |(in|for|on) SQL Server ( |2005|2008|2012|2014))

    Now I see some interesting titles. What if I want real words instead of random ones? There’s nothing wrong with random data for testing, but if I’m actually trying to compare data values in queries, it’s hard to focus on and remember random patterns. I could use the same OR values.

    (A|The|Top [3-7]{1}) (Blocking|Indexing|Tuning|T-SQL) (Tips|Techniques|Methods) (for| |in) ( |(in|for|on) SQL Server ( |2005|2008|2012|2014))

    Now I get some interesting, and perhaps memorable titles.

    2015-08-28 09_53_41-SQL Data Generator - TestSDG.sqlgen _

    Have Fun

    For much of our development work, the data itself doesn’t matter, but if needs to be easily discerned if you want to ensure that it’s easy to examine in queries. While random values work fine, I find them hard to deal with.

    I like the idea of using random words. Often the results are still nonsense, but they can be fun to work with. They remind me of a set of magnets my kids have on the fridge. Each is a word that will get randomly combined with others for humorous sentences.

    You can do the same thing with some RegEx and SDG.

  • Better Test Data Domains with SQL Data Generator

    This is a series on SQL Data Generator, covering some interesting scenarios I’ve run into. If you’ve never tried it, SQL Data Generator is a part of the SQL Toolbelt. Give it a try today with an evaluation today.

    I’ve been working more with SQL Data Generator (SDG) because it solves some problems that many software developers have with test data. Often each developer needs to create their own set of test data, with these being the common actions:

    • Use a backup of production, perhaps old.
    • Randomly insert a few values each developer comes up with
    • Use random data from SDG, a new project each time.
    • Load a known data set from production or test systems

    While I think small amounts of random data work well, I think the data should reflect (somewhat) the types of data in production. Totally random strings don’t work, but similar words, structures, etc. make sense.

    However having a consistent set of data for each developer is a great idea. SDG can consistently generate data sets, but to make them meaningful, you might want to have control over the types of data inserted.

    Using Real Words

    I talked about the difference between random words and real words. However, what if you want to include specific types of items?

    Let’s evolve some data. If I have a varchar(500) column, SDG defaults to this:

    [A-Z0-9]*

    Which gives me this:

    2015-08-28 10_03_55-New notification

    That’s not great if I wanted to examine specific rows and determine if they were being returned by a query. This is just too random and hard to verify.

    However I have options. For example, I could use the “Insert File List” item. This gives me a list of files that could be helpful. In this case, let’s choose “Color”.

    2015-08-28 10_05_33-SQL Data Generator - Fun_Article_Titles_Words.sqlgen

    I see this in the RegEx box.

    ($”Color.txt”)

    Now my test data looks like this:

    2015-08-28 10_06_14-

    What’s in “color.txt”? Let’s see. The file is under the Data Generator 3 folder, in a Config location. I see lots of XML and text files.

    2015-08-28 10_08_09-Config

    If I open Color.txt, I see what I expect.

    2015-08-28 10_08_17-Get Started

    Now, let’s experiment. Let’s create a SQL Server file. I’ll put values in like this:

    2015-08-28 10_08_17-Get Started

    I need to change permissions on the config folder to allow saving, but I put it there.  I also had to close and re-open SDG to pick up the new file.

    Now I’ll add that to the RegEx box.

    2015-08-28 10_15_44-SQL Data Generator - Fun_Article_Titles_Files.sqlgen _

    That’s cool. What if I made a file with a number of random words in it. Like a dictionary of sorts. I could do this. I create dictionary_small.txt.

    2015-08-28 10_22_10-Get Started

    Now I include that a number of times.

    2015-08-28 10_23_17-New notification

    Those are some great descriptions. I’m sure I could have fun with this in other ways as well. Let’s create some good and bad data for a cleaning operation.

    2015-08-28 10_28_38-New notification

    The ability to include data from flat files is a great option in SDG for putting together a data set that developers can actually use, understand, and count on for loading up new databases or tables, especially when creating quick code branches to test something out.

  • Maturing Your Database Development Process–Version Control

    At Redgate Software, we have a progression of the stages of a database development pipeline. These are the various ways in which you can better engineer your database development to ensure smoother releases to production, with less issues. There are five stages:

    • Manual (S0)
    • Source Control (S1)
    • Continuous Integration (S2)
    • Release Management (S3)
    • Monitoring (S4)

    As I travel around, speaking on these topics, I find many people working in development stops that are really at the S0 level.

    For databases, that is. For their .NET or Java or PHP software, quite a few are at S2, and maybe working towards S3 in many projects.

    That’s a disconnect, and it’s one that we’d like to see changed at Redgate. Certainly we can help and we’d like you to use our products, but more, we want to see better development all around.

    We’re Trying to Help New York City

    In a few weeks, on August 27, 2015, I’ll be in New York to help teach our Database Source Control workshop. Ike Ellis (Crafting Bytes) is teaching the class, and I’ll be there to support him and run the labs. This is a course that Grant Fritchey, myself, and a few others at Redgate Software have built.

    This is the chance to learn how your organization can implement version control for your database, just as most of your developers probably already have for the other software you write.

    We’ll cover setting up Source Control, deploying changes from versions, branching, merging, and more. This is a great hands-on introduction to stabilizing your database development. We’ll provide a VM with labs that you will actually complete.

    We’ve put this first step to building a DLM pipeline on sale for $100. If you’re close to NYC, consider taking a day off and joining us at the Microsoft office in Manhattan for a little database education.

    If you can’t make this workshop, look through our schedule and join us somewhere at a future time.