Category: Blog

  • Altering a column to add NOT NULL

    I had to do this recently and needed to look up the syntax as I couldn’t remember it. I don’t do this often, but I was working on a particular item and wanted to test this.

    I had a table, something like this:

    CREATE TABLE SimpleTable ( MyID INT NOT NULL PRIMARY KEY , MyChar VARCHAR(200) , [Status] TINYINT );

    I decide that the [Status] column shouldn’t be NULL and decide to ensure it’s always got a value. I don’t want to rebuild the table, I want to ALTER it. I use this syntax:

    ALTER TABLE dbo.SimpleTable ALTER COLUMN Status TINYINT NOT NULL;

    That’s it. I do this and the column now no longer accepts NULL values.

    Of course, if there’s data in there, I need to set those values to something that isn’t NULL before I can do this, but that’s a separate topic.

    By the way, I remembered most of this syntax. What I forgot is that I need to include the datatype in there to make this change. There are a number of restrictions with this command, so be sure that you read carefully before you try to make changes. If you do this in SSMS, you might end up with a script for a new table, which may not be what you want to occur in a production environment.

    Reference

    ALTER TABLE – https://msdn.microsoft.com/en-us/library/ms190273.aspx

  • The May Blogger Challenge–Continuing On

    Last month I participated in Ed Leighton-Dick’s April Challenge. My four posts were tagged the April Challenge, and this month I plan to continue, and hopefully get a few more people to up their blogging.

    Building on April

    To make the next step in starting to blog regularly, I’d like to see people in May continue with their weekly blogging, but do one more thing: write one additional post.

    This additional post I’d like to be one of the T-SQL Tuesday topics. Pick one from the list of past choices and write a post. Feel free to title it with the T-SQL Tuesday number and post it. It really doesn’t matter when you wrote it. The whole idea is to just write.

    Getting Started in May

    If you didn’t participate, or you struggled to get 4 posts, get started in May. Write one post per week and publish it. You can tag it the #SQLNewBlogger or you can just send a note to myself or Ed. We’d like to know what you’re doing.

    If you struggle to write, do one of these two things:

    • Make a note, send yourself an email, whatever, when you close a ticket or complete a section of code.
    • Use one of my topics

    Either one of these things work. I’d prefer you do the first one and just make a note when you do something. I’m sure you do something at work. Maybe it’s check logs, maybe it’s solve a problem with an instance, maybe it’s write a report. Anytime you do something, make a note.

    Then write about that note in a weekly session.

    If you are still struggling for topics, here are a few that I’d like to see you tackle in May:

    • Where do you use a unique index?
    • Generate a script after adding a column in the SSMS table designer
    • Query for the list of recent full backups in msdb for a single database
    • Show how to join two tables.

    Pick one and write. Set aside a 15 minute session a week to write, and work on a short, < 1 page, post.

    Good luck, and hope to see you blogging in May.

  • Implementing Continuous Integration in Redmond

    On May 15, 2015, Redgate Software and one of our partners, Northwest Cadence, will be presenting one of the DLM Training Workshops I helped build in Redmond, WA. I’m excited to be traveling up to WA for the event and helping support Dan Wood as he delivers the training on Continuous Integration (CI).

    This is our Database Continuous Integration workshop, and it’s a great way to learn how you can take your database code and get it automatically tested and built in a CI process. CI has taken hold in many parts of the software industry, but not so much databases.

    This workshop uses the Redgate tools, which make the process easier. However you can just use concepts with your own scripting or other tools. Our goal here is to help you get comfortable with the idea of CI and

    Requirements

    The workshop assumes you have your database in a version control system (VCS). If you don’t, then you should. We have a workshop on using source control with databases as well, but really you should just script our your database and put is in SVN, Git, or something. Or just use SQL Source Control, which makes it really easy.

    The other requirement if you have a laptop with you. We’ve built a number of labs, and we really, really want you to try and implement this yourself. We’ll provide a virtual machine up in the cloud, but we want you to have the chance to actually do the work.

    Register and Learn

    You can register today and purchase a ticket if your company is interested and you want to get some hands on experience with the technology. If you want to learn how to better engineer your software development on SQL Server, and haven’t given this a try (or are worried about it), think about coming.

    Register today

    SQL Saturday #393 – Redmond

    Our workshop is the Friday before SQL Saturday #393 in Redmond, WA. That’s a free event, and you can come there as well. I’ll be delivering a talk there, hopefully on testing, which is certainly important to CI.

    Either way, you can get a full day of in depth training on Friday at the workshop, and then a variety of topics on Saturday at the SQL Saturday event.

    Hope to see you there.

  • The Lineup

    Can you pick me out?

     

    lineup