Category: Blog

  • 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;
    
    
  • OT: The Next STEM Generation

    Now, it’s not a Star Trek reference. I’m actually breaking a bit from life this weekend to try and move my son forward in life. We’ve arranged a tour of the University of Colorado – Boulder campus, specifically with an eye on the aeronautical engineering program. He’s interested in that area, and we are trying to give him options for university next year.

    I’ve hoped my kids would enjoy computers, and they do, but not like I enjoy them. They aren’t interested in building things with computers. They just want computers to do their bidding.

    My oldest wasn’t very interested in computers at all, though I was able to teach him some SQL for his college GIS class the last year. We worked on understanding how to query data, but he never really understood the concepts well and needed help regularly. However he did learn enough to be able to alter my queries to meet the changing needs of different data sets.

    My middle son is a math/science whiz, and spent a few weeks one summer learning programming at a camp. He built a few small applications, but beyond that he wasn’t interested in learning more. While he like chemistry and aeronautics, programming seems silly to him.

    My daughter is the most savvy in moving data around, building web pages for visualizations and working across platforms. She seamlessly will use Windows, OSX, iOS, and Android on any given day across her four devices without blinking. She moves and uses data all the time, but hasn’t ever wanted to do more. She has done well in math and science, and is on pace to get to calculus her senior year of high school.

    I do want to encourage kids to try STEM subjects, and feel comfortable. My daughter certainly has felt pressure, and has female friends that feel the same pressure, to not work in STEM fields. I’d like to eliminate that, but more importantly, I want everyone to try the topics and really get a chance to experiment.

    If you don’t like STEM topics, that’s fine. Find another area you do enjoy more, but at least give STEM a try.