T-SQL Tuesday is the blog party started by Adam Machanic (b|t) over a decade ago and is now maintained by Steve Jones (b|t) on tsqltuesday.com. On the first Tuesday of each month, a blogger hosts the party and suggests a topic. Anyone interested in the topic gets to blog about it. You have one week to write your blog post. It has to go live on the second Tuesday of the month. The host then compiles a list of posts and creates a blog post, for a summarized read. It is a great way to get thinking on subjects you may not have thought of, read other people’s ideas on the same subject, and also get a few people to visit your blog to read your thoughts. Many bloggers including me have used this to get started.
I am honored to be the host for June 2022’s T-SQL Tuesday.
My invite is about coding standards, or what I now call Linting Rules, for T-SQL. What are the T-SQL coding rules that are appropriate for where you work and what you do? If there are exceptions to those rules, state them too! If this is enough, read the blog party rules below and get started!!
- Your post must be published on Tuesday June 14, 2022.
- Your post must contain the T-SQL Tuesday logo (see above) and the image must link back to this blog post.
- Trackbacks should work, but if not please put a link to your post in the comments section so everyone can see your contribution! (My comments are moderated so please don’t worry if yours doesn’t appear right away, I will make sure it does!)
- If you are on twitter include the hash tag #tsql2sday – it helps with RT-s and visibility!!
More on why I picked this topic as below –
When I started out as a DBA two decades ago, I had a list of rules that I would carry with me into every job I went..these are things I look for in T-SQL code and try to enforce as standard. Some examples were casing rules, minimized usage of SELECT STAR, equating the right data types in columns, avoiding NOLOCK hint and so on. Standards ensure quality and consistency in code.
Standards differ for each firm, depending on what is appropriate for an environment..it is even possible to have varying standards in the same company, depending on the environment and what is appropriate for a database. This is an excellent article on what are the different components that comprise coding standards, and why we need them. I am also a big proponent of automated code checking for standards – there are lots of tools available for doing this – SQL Prompt, which is a personal favorite of mine, and many others as listed here.
Several tools currently do linting on many relational platforms, not just SQL Server. Almost all of them though, have rules that the author(s) think are best for the worlds they work in, and do not include other conditions which they have not encountered yet. A common example I like to use is unnamed primary keys on temporary tables. There is nothing inherently wrong with having an inline primary key constraint/index on a temporary table – but if you use Query Store, plan forcing on a plan that uses this temp table will not work simply because the constraint gets named differently each time. When I started to look for a linting tool for where I work – I ran into so many rules that were non-existent or not applicable to my environment with outside tools that I decided to write my own using ScriptDOM – a Microsoft-provided library that was created specifically for this purpose.
It would help greatly if we had a collection of rules that people use to pick from and enforce as appropriate for their environments. It will also help me to code some of these into ScriptDOM and put it out on GitHub, if the rule is one that ScriptDOM can find easily. So, re-stating the call for this month – What are the T-SQL coding rules that are appropriate for where you work and what you do? If there are exceptions to those rules, state them too!
13 thoughts on “T-SQL Tuesday 151 Invite: T-SQL Coding Standards”
Thanks for hosting this, Mala. My post is over at https://lobsterpot.com.au/blog/2022/06/14/coding-standards-or-values/
My post is here
Thank you for hosting, Mala
Here is my T-SQL Tuesday contribution for this month. Thanks for hosting Mala.
Thanks Mala! Here’s my entry:
Here is my post. Thanks for hosting, Mala!
Hi Mala, Thanks for hosting! here’s my post: https://debthedba.wordpress.com/2022/06/14/t-sql-tuesday-151-coding-standards/
My response: https://voiceofthedba.com/2022/06/14/t-sql-tuesday-151-coding-standards/
Hello Mala, thanks for hosting!
Here is my contribution:
Thanks for hosting Mala! Here’s mine (and not on your about page this time!) https://sqlstudies.com/2022/06/14/too-many-coding-standards-t-sql-tuesday-151/
Hello, Mala! I sent my response link yesterday, could you check the comments waiting for moderation?
I think I have found the answer: my previous comments were sent with the Twitter account, and it looks like this authentication method not working But the WordPress method is working. Maybe check this for the next or other recent newcomers? Anyway, thank you for the invitation, Mala! Here’s my contribution. (And pingback is not working also, I guess…)