SQLServerCentral Editorial

Building Small Habits

,

I was reading Kenneth Fisher's piece on constraints recently and was struck by the fact that this is one of those small changes you make to your coding that has big benefits. In essence, rather than being lazy and writing this:

CREATE TABLE mytable ( myID INT PRIMARY KEY, MyCol ....

You decide to explicitly add a few more characters. You note this is a constraint and you type this:

CREATE TABLE mytable ( myID INT CONSTRAINT PK_MyTable_MyID PRIMARY KEY, myCol

It's a small change, but it takes you from an object named PK__mytable__783FBF31F8293E74 to one named PK_MyTable_MyID, which is way easier to understand and debug when you have issues. More importantly, this is a DevOps move, where a developer can make it easier for operations people to understand the constructs and organization of a system that has moved to a production environment.

There are all sorts of little coding changes you can make that improve the way you write code, and perhaps make it perform better. Aaron Bertrand has a whole series of bad coding habits, and at SQLServerCentral, we've published a number of pieces on different ways to code better, such as removing cursors from your code.

By making some small improvements in your coding habits, changing to better techniques over time, you'll slowly improve your entire codebase and help yourself and other developers code more efficiently in the future. I'd even recommend as a team that you choose a single change to make, and begin implementing it across the next month or two. Then repeat the cycle again. In a year, you'll be amazed where you are.

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating