Category: Blog

  • T-SQL Tuesday #136–The Datatype Blog

    tsqltuesdayIt’s that time of the month again, and this time it’s an interesting topic. The invitation is from Iceland, where Brent Ozar has relocated for the foreseeable future. I’m slightly jealous, and wish I could go visit. I enjoy winter, and the pictures he’s posted look amazing. Definitely a bucket list trip for me.

    However, this month, he’s asking about data types. Are there some you love or hate, and I’ve got a thought on this. In case you wonder, there is a list, broken into types. Apparently MS went into a “categorize everything” frenzy in the docs, which is OK, but I often don’t intuit the way they’ve broken things down. I wish they kept a long list on a page somewhere that was easy to find.

    Naming Confusion

    It has been deprecated, but the timestamp type is still around. It’s not in the list, but it is mentioned as a synonym for rowversion. This is a unique binary number in each database, which is often used to detect changes in a row. If you have two people editing a row, and a change updates a rowversion column, then each can detect if that value is different from the original one. Handy in terms of client side conflict resolution, which can prevent last-writer-wins scenarios for applications.

    I haven’t seen it used lately, but in the 90s and early 2000s, I often saw code that checked this before letting a user make an update in some data entry application. However, this was often a “timestamp” column, which was constantly confusing to me as a DBA or developer. I kept thinking I’d get some sort of datetime stamp in there, rather than a binary value.

    This shouldn’t be a problem in the future, as timestamp isn’t really doc’d, though timestamp can be found on Google searches. 

    The other reason I dislike this type is that we can’t change it to rowversion. An ALTER TABLE … ALTER COLUMN doesn’t work.

  • Daily Coping 9 Mar 2021

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag. 

    Today’s tip is to start today by appreciating your body and that you’re alive.

    I spend a lot of time working on my body, getting exercise and movement, trying to stay fit for the future. I’m not as good with my diet, but I’m trying.

    In any case, I have some hard days. My body is sore, or as I age, different parts just hurt. In the last year, I’ve had days where I struggled to get comfortable or even walk.

    However, I appreciate that I’m fairly healthy, I can practice yoga, weight lift, or ski, as I did last week. I’m grateful I’m alive and well, when far to many have lost their lives in the last year.

    I’m taking a few minutes today to appreciate where I am and that I am here.

  • Logging Messages with Raiserror – #SQLNewBlogger

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    I recently ran across some people discussing how to log some information in a script. One person was using PRINT, which I often use for quick checks, but someone else noted the RAISERROR works well, and you can customize messages.

    For example, I can have this type of script:

    DECLARE @d VARCHAR(20);
    

    -- do stuff

    SELECT @d = CAST( SYSDATETIME() AS VARCHAR(20));
    RAISERROR('%s - something happened at this time', 0, 1, @d)

    This allows me to add information into an error message. I can certainly construct @d with other stuff and then use that in PRINT, but I could get out of order messages. If  I add NOWAIT, I can ensure my messages get returned immediately.

    There are lots of options with RAISERROR, which I still use in place of THROW at times. While I like THROW, I think it doesn’t always give me the options I want for error handling, such as logging to the Windows lots.

    SQL NewBlogger

    When I saw this, I realized that I didn’t know, or remember, some of the ins and outs of RAISERROR, so I spent a few minutes looking through docs and playing with the code. I then wrote this quick post to help me remember a bit more.

    Short and quick is a good way to structure posts. I didn’t walk about all the options or ways I can use things. I’ll do some of that in another post.

  • Daily Coping 8 Mar 2021

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag. 

    Today’s tip is to set an intention to live with awareness and kindness.

    The world changed a lot in the last year. I’m coming up on a year of coping with the COVID-19 pandemic, and a year of coping tips. Amazing to think about. Apart from the pandemic, we’ve had protests around the world, difficult political times, as well as individual challenges with more remote work and learning, as well as the difficulties in seeing our friends and family.

    Throughout that, one thing I’ve tried to learn, and struggled with at times, is to be aware and understanding of other. I don’t walk in other’s shoes, nor do I have their perspective. I am trying to appreciate that what might be easy or hard for me, could be completely different for others.

    I also try to be kind, and trust that others are doing their best, or at least the best they can at that time.

    Today, I’m reminding myself to carry that forward in the coming weeks and months.