Author: way0utwest

  • Adding the Constraint Name to the PK at the End of Create Table–#SQLNewBlogger

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

    A good habit to get into is to explicitly name your constraints. I try to do this when I create tables to be sure that a) I have a PK and b) it’s named the same for all environments.

    I can create a PK inline, with a simple table like this:

    CREATE TABLE Batting
       (
            BattingKey INT NOT NULL CONSTRAINT BattingPK PRIMARY KEY
            , PlayerID INT
            , BattingDate DATETIME
            , AB TINYINT
            , H TINYINT
            , HR tinyint
       )
    ;

    This gives a primary key, named “BattingPK, that I can easily see inline with the column.

    Not everyone likes this, and I do run into clients and customers that want the keys separated from the column. This is fine, and I understand that this explicitly calls out the keys separately from the column.

    This is an easy change to my code.  I move the CONSTRAINT part to the end, as a separate item in the column list, and add the column(s) that I want to use in the constraint.

    CREATE TABLE Batting
       (
            BattingKey INT NOT NULL
            , PlayerID INT
            , BattingDate DATETIME
            , AB TINYINT
            , H TINYINT
            , HR TINYINT
            , CONSTRAINT BattingPK PRIMARY KEY (BattingKey)
       )
    ;

    As you can see, inlining names for constraints is pretty easy, and it’s a good practice to get in the habit of adopting.

    If I didn’t do this, I’d get a system generated name, which is fine, but the constraint name would then be different on every system where I deployed this object. Since I often want to test something on one system and deploy on another, future coding gets much more complex than it is by just doing this from the start.

    SQLNewBlogger

    This was a quick 5 minute post for me, following a short session teaching a client how to add the constraint to their table code.

  • Mitigate Issues Early

    This is a great postmortem from Basecamp with a detailed explanation of a problem and how they are hoping to avoid issues with their service. Basecamp is a Software as a Service tool from 37 Signals that had an outage recently. Actually, the service was up and could be read, but new items couldn’t be added and existing items couldn’t be changed. That somewhat defeats the purpose of the tool. 37 Signals recognizes this and notes that they’re calling this downtime and not trying to get pedantic about the state of the service.

    I have sympathy here because I’ve gotten the same error in SQL Sever. I’ve reached the point where I had 2,147,483,647 items in a table. Any additional items caused an error, which some of you might guess. This is the largest positive INT value and if you’ve started at 0 and incremented all new rows, when you reach this mark, you can’t add more data. There are a few fixes for this, including moving to negative numbers or changing to a bigint type.

    The staff at 37 Signals knew this was an issue and had actually set a new default for Basecamp that used a bigint in MySQL and PostgreSQL. What they didn’t do is actually make the changes in their hosted Basecamp database because they thought they had more time. I’ve seen that before, often when an application runs at a higher workload than expected for a few years and DBAs aren’t paying attention. When staff least expects it, the INT will reach the max value an clients start complaining. I’ve had to respond to an urgent phone call about this in a few companies.

    If you use INT values that are being incremented in some standard way, I’d likely set some alert process that triggers when the value gets to 2 billion or so, depending on how fast you use the numbers. SQL Monitor can do this with a custom metric, and I’m sure other software can as well, including SQL Agent. Having some monitoring in place will help you plan and be prepared to address issues before they cause problems.

    Steve Jones

    The Voice of the DBA Podcast

    Listen to the MP3 Audio ( 3.5MB) podcast or subscribe to the feed at iTunes and Libsyn.

  • Early Bird SQL Bits Pricing

    You can register today and save for the next few days. It’s only £799 for the full SQL Bits 2019 conference until Saturday. If you’ve ever  been, you know this is the best SQL Server conference out there, at least, that’s how I feel, and I go to a lot of conferences.

    I won’t be there next year, as I have a conflict. I’m sad, because I really look forward to this event every year. Fingers are crossed for next year, as I’m hoping to make a vacation of it with my wife.

    Go ask the boss and register today. The savings alone pay for some of your hotel. You know you want to go, and you’ll learn a lot. Microsoft has a large presence, so you can get some tech support for those pressing issues.

    There are always great sessions, from some of the top SQL Server experts in the world. You can see the submissions, and those alone should convince you this is worth the cost. Nowhere else can you get a four day conference for this price.

    Register for SQL Bits and then you can get to work on the really important stuff: picking a costume for the party Winking smile

  • Building Better Training Opportunities

    Recently I wrote a piece about some advice on quitting over training budgets, or the lack thereof. It had some interesting comments, but one stood out to me because it’s something I’ve heard and seen before. One of the readers noted that their company had bought a subscription for employees to learn new skills, but few of them had taken advantage of the courses.

    I’m not surprised. Many people are tired at the end of the day. Many people are fairly satisfied with their jobs. They’re not great, but not horrible, and we enjoy solving problems most days. Most of us would like to continue working where we are, in a stable situation. Not all of us, but many of us want to go to work and get paid for doing so, without a lot of motivation to do more.

    That’s fine, and I understand the pressures and stresses from the rest of life that weigh you down. I do understand that there are times that most of us would like to get away from work when we can and enjoy time with family, hobbies, faith, and more. My advice is that those things are important, but so is your career. Make some time to improve and grow your career and skills, even if you plan to stick with your current job. You never know when things will change.

    With that in mind, I think buying a subscription to Pluralsight or some other training option without providing any motivation or incentive is a poor plan. There needs to be some goals or expectations, and hopefully some sharing of the learning experience.

    If you need motivation, or you want to motivate co-workers, what about a competition? Challenge each other to complete a module of a course and write some code. Whether that’s to script installs with Chef, create a CI pipeline, count words with Python, or write faster T-SQL, if you have a goal, you’ll do better. I’ve had companies where we scheduled group watching of training, and with a small competition at the end, we found more people to be engaged and active in their learning.

    You could even make this a part of the review process, though please don’t just make this a checkbox. Ensure that if you want employees to learn something, you ask that they complete a class and contribute something back. Teach others, build something useful, or benefit the organization in some way.

    When there is a little more motivation, there’s a little more effort, and that can go a long way towards improving the skills of your workforce.

    Steve Jones

    The Voice of the DBA Podcast

    Listen to the MP3 Audio ( 3.5MB) podcast or subscribe to the feed at iTunes and Libsyn.