Author: way0utwest

  • 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

     

  • Business Pressures

    I know a little something about building and scaling a system on the Internet. While SQLServerCentral isn’t the largest site out there, we’ve had lots of experience with growing a site while trying to manage a business. We were successful at it for years before Redgate Software purchased the site. I’d like to think we’ve continued to run the site successfully and balance the commercial needs with our goal of hosting a world class SQL Server community that educates the community on a daily basis.

    I thought back about our history and the way things have gone while reading an article on Github and some of the challenges they have faced they they try to build a business from their (primarily) free service. I certainly hope they succeed as I really like the Github model and only hope their investors are as enlightened and visionary as the founders of Redgate.

    There are constant challenges in running a business. No matter how good your intentions, the pressure to break even or turn enough of a profit to survive are always there. At the same time, there is just as much pressure from ethical business owners to keep their customers’ and clients’ expectations and needs in the forefront of their minds as they run their business.

    I have struggled with this regularly at SQLServerCentral and still do today. Serving the community while providing value for my boss (or making a profit to pay my salary in the past) are two conflicting goals. I think that things have worked out well, but I am constantly striving to maintain some balance between what is best for all.

    I do hope GitHub and many of the low cost services are able to transition and survive as they mature as businesses. Even if many of them can’t continue to provide the same services for free, I hope customers see enough value to pay for some level of service, and the sites survive.

    Steve Jones

     

    The Voice of the DBA Podcast

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

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