Category: Blog

  • Catch up with T-SQL Tuesday

    T-SQL Tuesday is a monthly blog party where we get an invitation the first week of the month to write on a specific topic for the second Tuesday of that month. Adam Machanic came up with the idea and he chooses the hosts.

    If you’re interested in hosting, contact him.

    While there’s a sense of community and participation here, and certainly the chance to showcase some of your knowledge for others, it’s also got another benefit.

    It’s the chance for you to learn something.

    Not by reading other’s posts, but by writing your own. This is your opportunity to bolster your own skills, and teach yourself something new.

    Don’t Worry About Timing

    I know many of you are worried about the pressure of producing something good. I know many of you will find that the first weekend of the month is really busy and you can’t write.

    That’s fine.

    I’ve got a list of all previous invitations and topics. Go back and pick one of them and write your own post today. Start working on it, teach yourself something, and put some thoughts down. Research what others have done by looking through the roundups. Get a friend to review the work and see if it’s readable and makes sense.

    Do that ten times. It might take you ten months, but I’m sure you can write something down about SQL Server once a month.

    When you get ten, start a blog and publish them. Use the T-SQL Tuesday tag, but I’d also encourage you to use the #SQLNewBlogger tag as well. Start showing your boss that you’re improving your skills. Be ready to impress you potential next new boss with a series of posts on SQL topics.

    Your career will be better off, and the world will start to see better software being written.

    Start improving your skills this weekend, or start documenting the learning you already do. Either way, start building a better brand for your career.

  • Window Functions at IT/DevConnections

    I’m honored to have been chosen to present again at the IT/DevConnections conference this September in Las Vegas. It’s being held once again at Aria, which so far has been the only conference center I’ve seen that handled the bandwidth needs of a tech conference.

    I’ve got a few sessions, but one is on windowing queries in SQL Server. It’s an intermediate T-SQL session, looking to get you started in using Window functions in your code. It’s good if you’ve never used them, and I expect I’ll get some developers at this session, perhaps more than DBAs.

    If you’re looking for advanced usage, this is the wrong place. I’m not covering complex scenarios. I’m just trying to get you started.

    If you can get your boss to invest in your career, this is a good conference to attend, especially if you wear multiple hats or are responsible for multiple roles. You can get the chance to see an amazing set of sessions from some of the best people working in technology. You can learn about SQL Server, Visual Studio, SharePoint, ASP.NET, C#, Powershell, Azure, Windows Server, and more.

    The event is in Las Vegas, which is always fun for me. I don’t gamble, but I can take a night and see a show, which is always fun. If you want to come out for a few days, Hoover Dam is nearby, some great hiking outside of town, and of course, lots of music at various venues.

    It will be a good time, and I hope to see some of you there.

  • Updating to Windows 10

    I’ve been cautious about Windows upgrades. Throughout my career, I’ve alternatively been interested in, and wary of, Windows upgrades. I beta tested Windows 95, and then adopted Windows 98 as soon as I could at a company with better multi-monitor support. I avoided Windows ME entirely, and upgraded to Windows 2000 a few months after it was released. I upgraded to XP late in the beta stage, and stuck with that for a long time, eschewing Vista as a fat, slow OS. I eventually ran it on a laptop, but my experience with Vista made me glad I hadn’t upgraded my desktop.

    However, with Windows 7, I adopted it on my desktop early. I loved the increased speed and slimmer feel of the OS. I was happy enough that I didn’t bother to go to Windows 8 for quite some time, really until 8.1 was released. Windows 10 has been similar. I haven’t been too worried about it, setting up a VM, but spending little time using it. The past six months have had me more concerned about stability than experimentation.

    That changed last week. I was informed on both machines of my upgrade status the first week of August. I looked at the upgrade screen for a few days, being slightly worried, and finally scheduled my laptop upgrade late in the week after a trip. I was a little worried, but the machine upgraded itself overnight and other than a new welcome screen, I haven’t seen much difference.

    Things went smoothly that after 4-5 days, I went ahead and upgraded my desktop as well. Again, very little difference that I’ve seen. When I hit the start menu, the whole screen doesn’t flip away, but since I tend to just type the first few characters of an app and hit enter, not much of a change. The bars underneath applications in the taskbar as nice, and certainly easier to see, but that’s a minor change. Control panel has moved, and it’s only annoying as I keep looking to the right side for the pop out menu before I realize I have a normal window already open.

    All in all, the Windows 10 upgrade has been smooth for me. Some of the changes in Windows 8 are changed back (like the power down options), but overall, the OS has really faded in the background for me. That’s how I like it. The OS is a tool. Just get things done.

    Your experience may vary, but so far it’s been a smooth upgrade with no issues for me.

    My upgrades were on:

    • Toshiba Z30, Windows 8.1
    • Custom built W8.1 desktop, upgraded from w7 -> w8 -> w8.1

     

  • T-SQL Tuesday #69–Encryption

    TSQL2sDay150x150This is a good T-SQL Tuesday topic for me. This month Ken Wilson asks everyone to write on encryption, which is a topic I’ve presented on quite a few times.

    You can participate, too. Take a few hours, learn something, and tell us what you learned. Let everyone know how you view this topic and grow your blog with a little new knowledge.

    T-SQL Tuesday is a great chance to force you to write a post on a specific topic. Your post needs to publish on the second Tuesday of the month, Aug 11 this month, to be included in the roundup from the host. However feel free to write about this topic anytime, and even include the T-SQL Tuesday title.

    CASTing Results

    A short post this month, as I’m a bit buried in a few things, but this is one of those encryption notes that I didn’t see well documented when I started working with the subject, and I’m hoping I can save you a few minutes of frustration.

    If you encrypt your data, it will be stored as a binary type. This is because encrypted data is supposed to be random, and not easily decrypted.

    Let’s imagine I have some simple setup like the code below. I’ll create a key, open it, and use it to encrypt some data that I’ll insert into a table.

    CREATE TABLE MyEncryptionTest( intsource INT, charsource VARCHAR(50), intencrypt VARBINARY(max), charencrypt VARBINARY(max));
    CREATE SYMMETRIC KEY Mykey WITH    ALGORITHM = AES_128 ENCRYPTION BY PASSWORD = 'M$test78';
    GO
    OPEN SYMMETRIC KEY MyKey DECRYPTION BY PASSWORD = 'M$test78';
    
    INSERT dbo.MyEncryptionTest
            ( intsource ,
              charsource ,
              intencrypt ,
              charencrypt
            )
    VALUES  ( 7, 
              'Spike' , 
              ENCRYPTBYKEY(KEY_GUID('MyKey'), CAST(7 AS VARCHAR(10))) ,
              ENCRYPTBYKEY(KEY_GUID('MyKey'), 'Spike')
            );
    
    SELECT top 20
     * FROM dbo.MyEncryptionTest;
    
    

    The results of this are that I get binary data:

    2015-08-04 22_10_22-SQLQuery1.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (76))_ - Microsoft SQL Server

    Now, the decryption routine for T-SQL doesn’t need to specify the key. That means instead of a *, I can use the DECRYPTBYKEY function and pass in the column.

    SELECT TOP 20
            intdecrypt = DECRYPTBYKEY(intencrypt),
            chardecrypt = DECRYPTBYKEY(charencrypt) ,
            intencrypt ,
            charencrypt
    FROM    dbo.MyEncryptionTest;
    
    

    This gives me this:

    2015-08-04 22_12_22-SQLQuery1.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (76))_ - Microsoft SQL Server

    Not quite what I want. What if I cast this back to an integer? After all, the output of the function is listed as an nvarchar.

    SELECT TOP 20
            intdecrypt = CAST(DECRYPTBYKEY(intencrypt) AS INT),
            chardecrypt = DECRYPTBYKEY(charencrypt) ,
            intencrypt ,
            charencrypt
    FROM    dbo.MyEncryptionTest;
    
    

    I see:

    2015-08-04 22_18_10-SQLQuery1.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (76))_ - Microsoft SQL Server

    Again, not what I wanted. However, since I know something about conversions, I realize the output is close to what I want. In fact, what I need to do is perform a different CAST before I perform my final one. Here I’ll decrypt the results as NVARCHAR first, then as an INT.

    SELECT TOP 20
            intdecrypt = CAST(CAST(DECRYPTBYKEY(intencrypt) AS NVARCHAR(30)) AS INT),
            chardecrypt = DECRYPTBYKEY(charencrypt) ,
            intencrypt ,
            charencrypt
    FROM    dbo.MyEncryptionTest;
    
    
    

    Now I see:

    2015-08-04 22_15_29-SQLQuery1.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (76))_ - Microsoft SQL Server

    If I do the same for the character column:

    SELECT TOP 20
            intdecrypt = CAST(CAST(DECRYPTBYKEY(intencrypt) AS NVARCHAR(30)) AS INT),
            chardecrypt = CAST( DECRYPTBYKEY(charencrypt) AS VARCHAR(50)) ,
            intencrypt ,
            charencrypt
    FROM    dbo.MyEncryptionTest;
    
    

    I’ll get the correct results.

    2015-08-04 22_17_11-SQLQuery1.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (76))_ - Microsoft SQL Server

    Note that if I take the character column and cast to nvarchar, I’ll get something different. Try it and see.

    And don’t forget to close your key.

    CLOSE SYMMETRIC KEY mykey;