Tag: syndicated

  • Verify those Backups

    It’s important that you backup your database. The most important thing you can do. However making backups isn’t enough: you need to verify those backups are good.

    A humorous short video from Grant Fritchey (b | t) and RedGate on why:

    Watch the video

    Ideally you verify every backup every day, but that’s not always feasible. At least make sure you’re doing one backup from every database at least once a month.

  • 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

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

  • SQL in the City – US 2012 Tour

    SITC_headerLast year I had the pleasure of speaking at two SQL in the City events: London and Los Angeles. It was a great time and I was hoping we’d do more events this year.

    We did, with 2 events in London in July of this year and now we’re about to embark on the US portion of our 2012 tour. Over two weeks in September and October the Red Gate crew, including myself and Grant Fritchey, will hit five cities.

    At each event we’ll have a few special guests speaking, people like Adam Machanic and Brent Ozar. The line up changes slightly in each city, so check the agendas.

    We also added another event on Nov 5, 2012, in Seattle, just before the PASS Summit. If you’re planning on going to Seattle that week, think about joining us on Monday for a free day of training.

    All these events are free, and I’m looking forward to them. I wrote a post about my views for each event, and you can check those out if you are interested. If you want to run with me, I’ll be up early in each city on the day of the event, and sometimes the day before.

    This is a free event. FREE to you, with lunch provided, snacks, and a refreshing beverage at the end of the day.

    If you are in any of these cities on this date, I’d be happy for you to attend and shake my hand.