Author: way0utwest

  • Join Our Networking Dinner in Seattle

    This is the third year that Andy Warren and myself are hosting a networking dinner in Seattle, just before the PASS Summit. If you are new to the Summit, or just interested in meeting some new people, we hope you’ll join us on Monday, Nov 5, at Gordon Biersch, located in the Pacific Place mall on Pine St. It’s just a couple blocks from the Convention Center.

    We don’t have anything formal planned, just a time and place for people to swing by, shake hands, introduce themselves and talk about what they do, or why they came, or just life in general. It’s a casual event that is just (barely) organized so you have a chance to meet other attendees on an off night.

    If you don’t have plans and want to attend, come on by. Please register so we have an idea of the number of people coming.

    It’s BYOD/BYOF (buy your own xxx), but there’s no fee to attend.

    I’ll be at SQL in the City – Seattle 2012 during the day, another free event, and then I’ll come by afterwards.

    Register today

  • Data Worms

    The FLAME malware
    Are we going to see more and more targeted cyberwarfare attacks in corporations? I wouldn’t be surprised.

    Effective data administration include backups. I would argue this is the most important part of managing your data since no matter what happens, backups give you the ability to recover your system. Whether it’s an accidental data modification by a user, a hardware failure, a natural disaster or some other event, having a copy of your data (or log) on some other system or media can be the difference between getting back to work and having to go find other work.

    For the most part we’ve been concerned over disasters that are random, and while they may be destructive, their effect is usually limited in scope. SQL injection attacks often affect a single system, and with a good backup, you can usually recover your data quickly. However that may be changing as the world grows closer together.

    The Shamoon malware has been causing problems lately and making companies rethink their incident response. The worm has wiped workstations and destroyed data. Destructive software is nothing new, but as more and more cyber warfare takes places at the government level, it’s likely that retaliation might target civilian targets, especially successful companies. I’d hate to think that destructive malware might target databases, but I’m sure it will. The SQL Slammer worm was a complete disruption of our database services for days at JD Edwards almost a decade ago, but it could have been much worse if that malware had been written to be destructive.

    We don’t have default names and passwords in SQL Server, but we should make sure all accounts have strong passwords. There’s also some value in not configuring all systems identically. It makes management easier, but it also makes a successful attack that much more successful.

    Steve Jones


    The Voice of the DBA Podcasts

    We publish three versions of the podcast each day for you to enjoy.

  • Creating a User Defined Table Type

    I saw a post about a user defined table type in SQL Server and I was sure it was a typo. I kept thinking the poster meant table variable, but when I searched the term in Books Online, I was surprised to find User-Defined Table Types as an entry.

    These types are essentially templates that you can build for easier code reuse. They work in procedures and functions, or even as table variables. The CREATE TABLE syntax includes allowances for using these types.

    I can see this as being valuable when you have a structure that you want to pass into a module of some sort in multiple places and don’t want to have to include the code each time. I’m not sure it’s a great benefit, but it does prevent subtle mismatches like one module using varchar(50) for a column and another using varchar(200).

    A simple create for this type would be:

    CREATE TYPE StateTbl AS TABLE
    ( StateID INT
    , StateCode VARCHAR(2)
    , StateName VARCHAR(200)
    )
    ;
    

    This gives me a template I can use. Note that I can’t add rows to this table:

    INSERT StateTbl SELECT 1, 'CO', 'Colorado';
    

    I get this error:

    Msg 208, Level 16, State 1, Line 1

    Invalid object name ‘StateTbl’.

    It’s not an object yet. I need to instantiate an object based on this template. I can do that in a procedure:

    CREATE PROCEDURE SortStates
      @S StateTbl READONLY
     as
    
    SELECT StateName
     FROM @s
     ORDER BY StateName
    RETURN 0
    ;
    GO
    
    

    Fairly simple stuff. I can easily call this procedure, but I need a set of parameters first.

    DECLARE @p TABLE (id INT, scode VARCHAR(3), sname VARCHAR(20))
    
    INSERT @p
     VALUES (1, 'NC', 'North Carolina')
          , (2, 'VA', 'Virginia')
          , (3, 'CO', 'Colorado')
    ; 
    EXEC SortStates @p

    However this doesn’t work. The table isn’t compatible (I did that on purpose). Let’s clean it up.

    DECLARE @p TABLE StateTbl
       (StateID INT
       , StateCode VARCHAR(2)
       , StateName VARCHAR(200))
    
    INSERT @p
     VALUES (1, 'NC', 'North Carolina')
          , (2, 'VA', 'Virginia')
          , (3, 'CO', 'Colorado')
    ; 
    EXEC SortStates @p

    It still doesn’t work. There’s a binding here. I need to use the (cleaner) AS syntax for declaration.

    DECLARE @p as StateTbl
    
    INSERT @p
     VALUES (1, 'NC', 'North Carolina')
          , (2, 'VA', 'Virginia')
          , (3, 'CO', 'Colorado')
    ; 
    EXEC SortStates @p

    This returns results:

    udtt_1

    This means that you can use these types to create cleaner code, and enforce some standards (preventing things like people declaring columns with different lengths. However it also means that you have another “type” to manage and ensure everyone is using.

    I’m not sure how useful this is, but it is a neat little construct.

  • Dress Like Steve

    I hate wearing suits and ties. One of my early jobs in technology required them, and my least favorite part of that job was the dress code. Almost as bad was a company that required a uniform: same pants and shirt every day. I didn’t mind a few jobs that required khaki pants and a collared shirt since I could have a little variety, but my ideal job, which I have now, lets me wear what I want. T-shirts, shorts, sandals, jeans, and more are acceptable in my office.

    These days when I put on a collared shirt, it’s usually one with with design of some sort on it. I have a nice collection of colorful shirts, and I often wear them to events. Can you find me in the picture below?

    SQL in the City Staff
    One of these things doesn’t look like the other…

    As we were planning the US tour of SQL in the City and talking about things we might giveaway, someone suggested adding a few shirts to the list of books, pens, balls, etc. I thought that if I were to give away some cool SQLServerCentral shirts to attendees, I ought to make sure that I was modeling one of the prizes all day. My boss agreed, and I got permission to go shopping.

    At each of the US SQL in the City tour stops, I’ll be wearing a new Hawaiian shirt. At the end of the day at each event, I’ll also be giving away 3 of the same shirt to three lucky attendees. You can’t win one if you don’t come, so if you are in any of the cities we are visiting, be sure to register and come get a free day of presentations from Grant, me, and a number of other speakers. I’ve got a series of blog posts on the events, and if you want to run with me in the mornings before an event, drop me a note on Twitter.

    Steve Jones


    The Voice of the DBA Podcasts

    We publish three versions of the podcast each day for you to enjoy.