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.

Posted in Blog | Tagged , , | Comments Off on Adding a Named Default Constraint to a Table: #SQLNewBlogger

Storage Enhancements

There was a time when I knew a lot about the various storage technologies available for a database. It was important when designing a server around the various requirements for size and performance balanced against the limitations of hardware.

The rapid growth of solid state storage and the adoption of storage area networks have changed the game for many of us. We no longer care or think about storage. It’s just a service that we consume in our databases, and while we might demand more IOPS capacity, we often don’t worry too much about how that’s provided to our systems.

I caught an article about IBM and a few enhancements to their offerings. They have a FlashSystem 5200, which is a way of taking their enterprise-class systems and packaging it in a way that organizations of all sizes can afford. In this case, they can get 1.7PB in a 1U package, which seems insane. I can remember working on an Enterprise 2U system that maxed out at 200GB worth of SCSI HDDs.

I wondered if this was a lot in today’s world. A few friends work for Pure Storage, and I’ve met some customers who were very impressed with their arrays. When I looked at a FlashArray//X70 from them, they get 2.4PB in 3U, so the IBM offering is more dense. In terms of IOPS, I’m sure they are both very fast, likely fast enough for most places I’ve worked.

What’s interesting is that I’ve found sysadmins way more concerned about specs and loving the Pure arrays more than the DBAs. DBAs (I think) are stuck with the hardware, and so they are always looking for what the bottlenecks are on a system and can I tune them down to a reasonable level. Or can I just get more storage or IOPs from whoever is in charge of storage?

The world of storage (and networking) has come so far in the last 30 years that the numbers today seem mind-bogglingly fast compared to even a decade ago. It makes me wonder why we have any performance problems at all. Unfortunately, all the hardware in the world can’t compensate for keeping too much data in expensive storage and writing bad code. A little query expertise and archiving structures would likely make all that hardware look as amazing in the real world as it appears in spec sheets.

Steve Jones

Listen to the podcast at Libsyn, Spotify, or iTunes.

Note, podcasts are only available for a limited time online.

Posted in Editorial | Tagged | 1 Comment

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.

Posted in Blog | Tagged , , | Comments Off on Just a few weeks to PASS on Tour and the Redgate Summit

Sabbatical 3 – A week of work

I hadn’t made many plans on the sabbatical, and that was fine with me. It’s been a busy year, and I wanted to be unwired and unwind. It turned out this has been a good test of retirement for me and I’ve enjoyed it.

However, we did have a big project on the books and decided to schedule it during my time off. This is my wife’s indoor riding arena.

It’s been on the ranch since 2010, but a very heavy hailstorm damaged it almost two years ago. A number of small holes in the fabric let rain in, which has worsened over time. We worked through an insurance claim to get new fabric and some installation compensation, but decided to do some of the work ourselves since the install cost was high. We did pay for a vendor consultant to help for a week, but my wife, kids, and did all the work.

This was scheduled during my sabbatical and it turned out to be a bigger project than expected. They told us to budget 2-3 days, but it turned out to be 6 for my middle son and I, with lots of help on the other days getting things done.

Here’s the fabric being cut by my son to be pulled off.

It took a day to unwind all the nuts holding things down and then cut down the fabric. A lot of labor, and more than needed, since a custom tool that they send for installs wasn’t available for us. I suspect the original crew didn’t save it for us.

However, the consultant asked if I knew a welder, and we do. The husband of one of my wife’s clients has a shop and has been teaching my daughter to weld. I bought a 7/8″ socket and a piece of pipe and my daughter went over there during the day. She returned with a custom made 20″ socket, which made the install easier later in the week. Here’s my kid using it.

Day 2 was pulling over the first piece of fabric. We used the tractor to do this during a time of low wind. We can pull up to about 10mph, but after that it’s too dangerous.

This was the easy part. We had to then pull the piece sideways to cover the truss. That’s a manual process, working around the edges, slowly pulling things right with 2″ webbing. Once that was done, we then wove in 1″ webbing between the frame and the fabric. We got this done on Day 2, and we were tired.

We worried a bit about getting this done, but on Day 3 we managed to pull both the 2nd and 3rd pieces. We did the middle, and then stretched it. We started weaving in the fabric, but had a moment of low wind, so we quickly pivoted and got the third piece pulled.

We managed to get it partially stretched and tied down before it got too late. Our consultant left and we worked to get the 2nd piece finished.

Day 4 was us working along. Once we got the third piece stretched, my wife and son were tightening wire that spends the edges of each piece of fabric. A few remote Facetime calls with our consultant had them working through it as I wove in the last piece.

A good view from above. My wife and daughter were a little scared about the height, so my son, a friend, and I did all the weaving above 10 feet.

A shot of my son and I working.

We rented a second lift late on Day 2 and I wish we’d done it earlier. Things went much faster with two lifts.

Day 5 was the final weaving and tightening things down. We closed the day with most everything done.

Day 6 was me cleaning things up, picking up trash, patching a couple holes in the ends while we had the lift and my son tightening the nuts (shown above).

We finished just in time as Day 7 was my wife and I heading to Cancun for a well deserved break.

Posted in Blog | Tagged | 3 Comments