Tag: syndicated

  • Building an algorithm

    When I was in college, and even high school, all of my computer science classes required me to build algorithms. Often they were simple things, like implement a sort, or reverse a string, or shuffle a deck of cards. Those seemingly silly and trivial exercises, however, build the skills of pattern recognition and implementation in computer science. Sometimes I think we don’t do enough of that for people that are tackling computer careers these days.

    I saw a post from someone that had an incrementing column, an identity, that impacted another field. Basically whenever the first column reached “10”, you wanted to add one to the second column.

    Easy, right? I think so, and to show someone how they might create an update statement, or even see the pattern, I built a quick tally table.

    SELECT Top 205 IDENTITY(INT,1,1) as N
      INTO Tally 
      FROM master.dbo.syscolumns SC1, master.dbo.syscolumns SC2

    From there, I then looked at the pattern. Every 10 items, I need to add one. That’s a pattern, and the way that pattern is easily discerned in math is with a modulo operation. To the rest of the world, that’s a remainder. If you look at the pattern of remainders of an increment divided by 10, it’s this:

    n           modulo

    ———– ———–

    1           1

    2           2

    3           3

    4           4

    5           5

    6           6

    7           7

    8           8

    9           9

    10          0

    11          1

    12          2

    13          3

    14          4

    15          5

    16          6

    17          7

    18          8

    19          9

    20          0

    21          1

    22          2

    from this code:

    SELECT Top 205 IDENTITY(INT,1,1) as N
      INTO Tally 
      FROM master.dbo.syscolumns SC1, master.dbo.syscolumns SC2
      
    
    SELECT n
      , n % 10
     FROM Tally  
      
    DROP TABLE tally

    That mans that we can see each time there is a zero remainder, we want to perform an increment. So essentially if you detect an update, do a modulo, and get a zero, then you update the next column.

    It gets a little more complicated if there can be multiple rows updated or added at once, but here is the overall code that essentially builds a table of numbers that increment for each 10 on the previous value.

    SELECT Top 205 IDENTITY(INT,1,1) as N
      INTO Tally 
      FROM master.dbo.syscolumns SC1, master.dbo.syscolumns SC2
      
    DECLARE @b INT
    
    SELECT @b = 1
    
    SELECT n
      , n % 10
      , @b
      , n
      , @b + (1 * (n / 10)) 'col b'
      , CASE WHEN (n % 10) = 0 THEN 'add 1' ELSE '' END 
     FROM Tally  
      
    DROP TABLE tally

    You end up with this:

    n                                   n           col b      
    ———– ———– ———– ———– ———– —–

    1           1           1           1           1          
    2           2           1           2           1          
    3           3           1           3           1          
    4           4           1           4           1          
    5           5           1           5           1          
    6           6           1           6           1          
    7           7           1           7           1          
    8           8           1           8           1          
    9           9           1           9           1          
    10          0           1           10          2           add 1

    11          1           1           11          2          
    12          2           1           12          2          
    13          3           1           13          2          
    14          4           1           14          2          
    15          5           1           15          2          
    16          6           1           16          2          
    17          7           1           17          2          
    18          8           1           18          2          
    19          9           1           19          2          
    20          0           1           20          3           add 1

    21          1           1           21          3          
    22          2           1           22          3          
    23          3           1           23          3      

    If I had started at zero, you’d see a more traditional increment of 0 for column b to start with.

  • The Mentoring Experiment

    Andy Warren (LinkedIn | Blog | @sqlandy) and I had an idea for a way to give back to the community and help people. It’s the Mentoring Experiment, and we are taking applications from people through April 20.

    If you’re interested in finding a mentor, and want to take a chance on getting picked, check out the site and submit your application.

    http://thementoringexperiment.org/

  • Close, but no MCM Cigar

    I failed.

    There’s no other way to say it, but I’m not really disappointed or discouraged. I’m actually fairly upbeat about it. I went into the Microsoft Certified Master test thinking that I’d fail because it aims to be a high end certification. I felt like I had a huge knowledge gap going through the study resources on the SQLskills MCM page.

    I plugged away, and learned a lot. I listened to content on long car trips and airplane rides. I read white papers at night and while waiting for kids at various events. I practiced working through some of the code examples, and came up with new ideas along the way. And I got a lot of notes, so many notes that I didn’t even review half of them as the test got closer.

    And I was surprised. As I wrote about my test experience, I think I was well prepared, and I knew more than I thought. Every question made me think and made me deduce some solution, but very few of them had me throwing up my hands and feeling like a complete idiot.

    My score was close to passing. It wasn’t the single digits I joked about on Twitter, nor was it the low 200-300 score I was thinking I might end up with. The passing score is 700, though it isn’t clear if that’s out of 1000 or 800 or 743. We don’t know how the exam is scored, and I’m not sure if that’s good or bad, but that’s a separate blog.

    In my case, I got a 620 with bar graphs that listed my relative strength in a few areas. I scored highest in Scalability and Availability, with my graphs about 8/10 of the way across. In Recoverability and Managability I had about 7/10 of the total distance. That’s not surprising since I think those administrative areas are my strongest skills.

    In security I was about 6/10, which is a little surprising. I thought I knew SQL Server security very well, but I’ve always been a “practical” security guy, and not necessarily conforming to what the MCM might see as the best way to implement security. Definitely need to work on this area a little more. In Performance, I was about halfway, which is probably true. Without spending a lot of time on this in a practical sense in recent years, I’m relying on my memory in studying and not using field-skills.

    Developer Support, which I assume means XML, Spatial, CLR, and other similar code oriented areas I was the lowest, about a 4/10. That’s not surprising since I don’t write a lot of code and really haven’t spent much time in those areas. They feel to be a little outside of the core of what I really enjoy in SQL Server, and I’m sure I didn’t focus here all that well. I know I listened to the SQL CLR prep four or five times and was still slightly confused as to what was covered.

    There were no areas that were incredibly weak, but a few that need improvement, and I know that I have a few things in the manageability to work on after the test. I won’t go into specific areas, but suffice it to say that one particular topic had 3 or 4 questions and I struggled with them talking about a certain implementation of the technology that I hadn’t spent much time on.

    Moving On

    What do I do from here? I was thinking this was a one-shot deal for me and I’d get an assessment of where I stood. I definitely got that, and the results seem to mirror what I would have thought were my strengths and weaknesses. My higher-than-expected score has me wondering a little about which of these is true:

    · I know more than I thought

    · The exam doesn’t test real world skills as much as I thought

    It’s hard to know which is true. I don’t do a lot of real world work, but I read a lot, and I talk with many people about what real world problems and solutions they use. So I have a wide set of knowledge, but not necessarily deep in places. The exam can only test me on the areas it tests me, and with a limited time, there is only so much it can test.

    I have the chance to take the exam again as there are still vouchers available and I think I will. I’d like to try again to pass it since I have a little competitiveness left in me and I thought I was close after taking the exam. If I can improve in a few areas, I’d think I would do better, though I expect different questions and would need to review all the material again.

    The lab? That’s a whole ‘nother story. The lack of practice in some areas might have me fumbling around more than I could afford in a limited time frame. I have less confidence I would pass that, though more than I would have had a few months ago. That’s if I could sit still for 6 hours and focus on SQL Server that long.

  • T-SQL Tuesday Reminder – Coming next week

    Matt Velic is hosting T-SQL Tuesday this month. You have a week to get a post ready on the apply operator.

    To help you out, here’s the BOL page on Using the Apply operator. It’s an operator that essentially lets you invoke a table valued function for each row of a result set. Not necessarily the most efficient way to get some things done, but it can be a powerful way of combining complex data that requires a function to interpret.