Tag: syndicated

  • Adding a Named Default Constraint to a Table: #SQLNewBlogger

    As part of a demo recently I was adding a default value to a new column with a simple DEFAULT and a value. Under the covers this creates a constraint, however, I want to ensure this is named explicitly and not auto generated. This post shows how to do this.

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

    Setup

    Let’s create a simple table like this one:

    CREATE TABLE dbo.OrderHeader (
    OrderHeaderID INT NOT NULL CONSTRAINT OrderHeaderPK PRIMARY KEY,
    OrderDate DATETIME,
    CustomerID INT
    )
    GO

    Now I want to add a Created column to the table, with a default value of the current date and time. I decide to do this with an ALTER TABLE statement. In the past, I’ve done this with this code:

    ALTER TABLE dbo.OrderHeader 
    ADD Created DATETIME DEFAULT GETDATE()

    The problem is this creates a constraint with a system generated name. If I deploy this code to different systems, I get different names. If I need to change the constraint or drop it, I have to query to find the name as it isn’t explicit. You can see this below.

    2025-05_line0061

    What I’d rather do is have a named constraint that makes sense to me. Let’s drop this column and do a better job. However, I cant’ just drop the column because I need to drop the constraint and that means I need to get the name.

    2025-05_line0063

    That’s the problem I’m trying to solve. Here is what I need to do.

    2025-05_line0064

    Now that I’ve dropped this, let’s add it back with an explicit name. This is simple SQL, and easy to add, just like I can do for Primary Keys. We’ll add a CONSTRAINT keyword and name before the default.

    ALTER TABLE dbo.OrderHeader 
    ADD Created DATETIME CONSTRAINT df_OrderHEader_Created_Getdate DEFAULT GETDATE()
    GO

    When I run this, now I see a named constraint.

    2025-05_line0066

    Note that I’ve named this for the column as if I need similar constraints in this table, they need to be uniquely named. This is in the database, not the table, as all constraints are stored in sys.default_constraints.

    Do this and your database deployments go easier, especially across multiple systems.

    SQL New Blogger

    This is a simple thing, but it’s a good coding practice and better software engineering than allowing the system to name things. I explained how to do this and related this to a real issue in database development: deployments.

    This post took me about 10 minutes, and it would likely take you about the same to start showcasing your knowledge. In today’s world, maybe you use AI to help you solve this problem and showcase that skill.

  • Just a few weeks to PASS on Tour and the Redgate Summit

    It’s just a few weeks until the PASS Summit on Tour in New York City. This is the first event in the series, and I’m excited to go back to New York City this year. I’ve been there a few times and this time my wife is coming so we can take a little vacation around the event.

    You can register here and come see some amazing speakers on Aug 18-19, 2025 for the PASS Summit. Aug 20 is the Redgate Summit, where we’ll be talking about our direction, research, and products. Make it a week and come to both events.

  • Speaking at the PASS Data Community Summit

    I’m honored to be speaking at the PASS Data Community Summit in Seattle this fall. I’ll be delivering a Professional Development session (Blogging for the Tech Professional), which might be more interesting this year with so many people looking for work. Blogging is a great way to show some skills, let managers perform some due diligence, and help drive the interview. If you can come, register now for savings.

    There are lots of great speakers that will be there as well, and it’s quite a lineup. The exact lineup for the main conference isn’t out, but the list of speakers is nice. There are also a great set of pre-cons to choose from as well.

    This is one of the best data conferences to attend and I’ve been lucky enough to go most years and learn lots while networking with fellow data professionals.

    Talk to your organization and make a case to come. Register early for savings, and plan on a busy week of learning, networking, and notes. Bring back practical tips, tricks, and ideas to your boss and they’ll send you again next year.

  • The PASS Summit on Tour in the Netherlands

    The PASS Summit goes on tour this year, with the final date the first few days of October  in the Netherlands, Utrect to be exact. This is the first event in the series, and I’m excited to go back to New York City for the event. You can register here and come see some amazing speakers on Oct 1-2, 2025.

    2025-06_line0088

    The lineup is small and short, but it’s a one pre-con day with two half-day sessions and then a one full day of hour long sessions. The pre-cons include Fabric, leadership, performance tuning and more. All from industry experts. The regular sessions are across four tracks with a variety of things you can learn during the 5 time slots throughout the day.

    There is also a Redgate Summit on Friday. That’s got Redgate specific content, but if you’re interested (or a customer), stay an extra day for that as well.

    If you’re near Dallas, or can convince your boss to send you, register today and join us on tour. The larger main event is still in Seattle, and if you prefer that, come for a full week in November.