Problems displaying this newsletter? View online.
SQL Server Central
Featured Contents
Question of the Day
The Voice of the DBA
 

The Code Review Checklist

Early in my career as a developer, I was required to follow a formal process to get the code I'd written deployed to production environments. Each time I'd written code, I had to document what I'd tested and then print out the relevant sections of the codebase. I needed to find two other developers to spend 10-15 minutes with me in a meeting, going over my code, each of us with our own paper copy. Almost like a dissertation, I had to answer questions and defend my work, with problems being marked on paper for me to go fix.

Over time, I learned that different developers reviewed code in different ways. Some spent more time on standards and formatting. Naming and the visual structure were more important to them, so if I wasn't confident in my work, I'd pick them and spend time ensuring the formatting was correct. Or sometimes, I'd mis-format it, so they would tell me to go fix that and not look at what the code actually did. Others were better at examining algorithms, and I often used them to help me learn, with them digging into my logic and helping me understand whether I'd included enough error handling, considered edge cases, or written code that performed well.

Often the mood I was in, and the pressure to meet a deadline might have me leaning one way or the other. Of course, there were plenty of times I just had to go with whichever two developers had time to review the code.

There was an inconsistency in code reviews, and I breathed a sigh of relief in future jobs where we didn't formally review code. In fact, in quite a few positions where I wrote C++, VB, or FoxPro/Clipper, my code was never reviewed, nor was there formal testing. Other developers and I often had to rework sections of code regularly, which led me to implement better testing of my own code. I didn't adopt formal frameworks for some time, but I did save off test scripts for code in our Visual SourceSafe repository to ensure I could test code.

These days pull requests and code reviews are commonplace, at least among many software developers. Not so much in the database world, but I do find customers that believe in testing and I regularly preach this to others. I'm also glad that Redgate has built-in static code analysis and linting into its products, though I wish we had better (and easier) unit testing support for database code.

For those of you out there writing code, do you go through any sort of code review process? Is it consistent? Is there a checklist of sorts? I have found that different people have their own internal checklists, but I rarely see anyone with a more formal checklist, or even a set of lists for what to check in different types of code. Even in unit testing, I don't often see people approaching their tests in a methodical manner.

Checklists have been shown to be beneficial in the healthcare field where staffers are overworked and handoffs are frequent. Using a set of checklists can improve patient outcomes. I suspect that a good set of checks for code might do the same thing. However, I find that a lot of database developers are reluctant to adopt any formal testing practices.

A view that reminds me of .NET and Java developers in the early 2000s.

Do you have a checklist (actual or mental) that you go through for your own code? For anyone else's code? Or do you think formal testing of SQL code is even worth the effort. Let me know today.

Steve Jones - SSC Editor

Join the debate, and respond to today's editorial on the forums

 
 Featured Contents
SQLServerCentral Article

GIT Configuration and Automated Release for Azure Data Factory

Sucharita Das from SQLServerCentral

Learn a step-by-step method to save your ADF pipelines in Git and automatically release new changes to test and production.

Technical Article

Explore Natively Compiled SQL Server Stored Procedure Execution Plans

Additional Articles from SQLServerCentral

In this article, we look at execution plans and performance of a natively compiled stored procedure versus a traditional stored procedure.

Technical Article

What Is Good Database Design?

Additional Articles from SQLServerCentral

Find out how good database design is essential to ensure data accuracy, consistency, and integrity and that databases are efficient, reliable, and easy to use.

Blog Post

From the SQL Server Central Blogs - The 5 Best SQL Course for Beginners – Reviews and Guide

Tracy McKibben from RealSQLGuy - Helping You To Become A SQL Hero

In the technologically driven world of 2024, more individuals are finding themselves drawn towards the intricacies of database management. Central to this booming sector is SQL, a programming language exclusively...

Blog Post

From the SQL Server Central Blogs - Using the Pure Storage PowerShellSDK2 - Part 1 - Connecting to FlashArray

aen from Anthony Nocentino Blog

Welcome to our blog series on using the Pure Storage PowerShell SDK2. In this series, we will provide you with practical insights and examples on how to harness the...

Azure SQL Revealed

Azure SQL Revealed: A Guide to the Cloud for SQL Server

Site Owners from SQLServerCentral

Access detailed content and examples on Azure SQL, a set of cloud services that allows for SQL Server to be deployed in the cloud. This book teaches the fundamentals of deployment, configuration, security, performance, and availability of Azure SQL from the perspective of these same tasks and capabilities in SQL Server. This distinct approach makes this book an ideal learning platform for readers familiar with SQL Server on-premises who want to migrate their skills toward providing cloud solutions to an enterprise market that is increasingly cloud-focused.

 

 Question of the Day

Today's question (by Steve Jones - SSC Editor):

 

Rollback or Not?

I have a number of rows in my SQL Server 2019 database in the AddressTable table. I run this code:
 BEGIN TRAN
 TRUNCATE TABLE dbo.AddressTable

 ROLLBACK
 
 SELECT top 10
 *
 FROM dbo.AddressTable AS at
How many rows are returned?

Think you know the answer? Click here, and find out if you are right.

 

 

 Yesterday's Question of the Day (by Steve Jones - SSC Editor)

Restore and Upgrade With NoRecovery

I have a SQL Server 2019 backup. I decide to restore this to a SQL Server 2022 server using the NORECOVERY option since the STANDBY option doesn't work. What happens when I run this?

Answer: This works fine and the restore completes, leaving the database in Restoring status

Explanation: This works fine with the database in Restoring status and is the way many database moves + upgrades are accomplished. Additional log backups from the 2019 database can be restored on top of this restore. Ref:

 

Discuss this question and answer on the forums

 

 

 

Database Pros Who Need Your Help

Here's a few of the new posts today on the forums. To see more, visit the forums.


SQL Server 2016 - Administration
Monitoring Transaction Log usage? - I'm curious is there any way for me to monitor the TLog generation in my database? I am trying to pin point which sessions/SQL queries which generated huge amount of transaction log. I have alerts to notify if log space is running out, but I'm trying to find out which particular session or which query […]
SQL Server 2016 - Development and T-SQL
Insert a new record in a temp tableq - Hi, Not sure if this is possible. I'm looking to insert a new row into a temp table if a field on the record read is a specific value. Example Row reads Name, Address, Date, Flag first row = Jane, 1 Main St, 10/5/23, z second row = Tarzan, 12 Main St, 10/4/23, x Now, […]
Administration - SQL Server 2014
sources\sxs is not a valid installation folder - I'm trying to add a SQL feature via programs features - SQL Server - change - add. I have mounted the ISO successfully. When I click add it asks me to specify the installation folder so I browse to J:\sources\sxs and click ok. I keep getting the message that sources\sxs is not a valid installation […]
SQL Server 2019 - Administration
Replication subscription attempt fails with master key Error: 15581 - Hello experts, I'm trying to create a replication subscription and got this error. Does anyone know how I can fix it without inadvertently messing up any encryption that the SQL Server has? Please create a master key in the database or open the master key in the session before performing this operation. Changed database context […]
SQL Server 2019 - Development
T-SQL | Group Invoices with concern dates that overide the issue date - I have a table with Invoice Documents per Project, in which i need to get statistics per project , year , month with sql. The difficulty is that for some of the invoices the user will have entered concerned dates that must be override the issued month of the Invoice Document and must be splitted […]
Select statement result change as insert statement values - Hi All, Looking for following results. Can you please help in this. Original 1 A US Expected result 1,'A','US'   create table #tbl_Test (ID int, Name varchar(20),City varchar(20)) insert into #tbl_Test values (1,'A','US') Select * from #tbl_Test Expected result 1,'A','US'
Select a distinct list of values from tables, return the dataset - I am trying to select a distinct list of values from multiple tables, combine them into a single table with all data starting in row one instead of the data being returned on new rows for each distinct data set. This is what I am current getting by using a union: This is how I […]
Setting up a view with parameters - Hi Folks, I'm not very well versed in SQL so I come here to the experts for advise. I have a nice little query that is currently using hard coded values for customer name, start and end dates.  I need to be able to pass those values as parameters which I don't know how to […]
Stored procedures in Analysis server - I have written a stored procedure to format data and return them as a table with custom columns. In this sp, I use #temp table to do some formatting / calculations. Now our powerBI report writers want to access to this SP from Analysis service. For them our admin created SQL analysis service. PowerBI users […]
How to check if SQL is installed on any of my multiple windows servers - I have about 400 windows servers. How can I check if SQL Server is installed on any of those servers. Thanks.
Correct syntax for this Contains statement - I want to search a table alias doc, column name Result, where doc.Result is full text indexed, using Contains, and I want to find where there is the term BSA and a % sign (percent sign, literally) within 5 words of each other. Do I have to escape the % sign like [%] ?  that seems to come back […]
Reporting Services
SSRS server randomly get disconnected (sql server 2016) - I have a problem with my SSRS server that randomly can't connect to my data source. It works all the time but sometimes I get an error in my reports that indicate that the server failed to connect. Any tips or leads to identify the source of this problem? Here is my connection string: Data […]
General
Fetch API in Node.js: Making HTTP Requests -   I'm working on a Node.js application where I need to make HTTP requests to external APIs. While I'm familiar with using the Fetch API in browsers, I'm not sure how to use it in a Node.js environment. Here's a simplified example of what I want to do: const fetch = require('node-fetch'); async function fetchData() […]
SQL Server 2022 - Development
Query web API and return JSON data - curl -X GET "https://api.server.com/v1/markets/quotes?symbols=AAPL,VXX190517P00016000&greeks=false" \ -H 'Authorization: Bearer ' \ -H 'Accept: application/json' How do i run this Rest Json API in sql server directly ? I believe its a combination of using he below, but i could not figure out the last syntax. sp_OACreate, sp_OAMethod sp_OAGetProperty Python version is here : # Version 3.6.1 […]
How to get 2nd max value if 1st max is null - Hello All, I have written below query to get agent data who completed max tickets for each group. But some times the agent email address is null or blank. So In that case I need to consider the 2nd max tickets completed agentname. If this email also null then 3rd max tickets completed agent. Could […]
 

 

RSS FeedTwitter

This email has been sent to {email}. To be removed from this list, please click here. If you have any problems leaving the list, please contact the webmaster@sqlservercentral.com. This newsletter was sent to you because you signed up at SQLServerCentral.com.
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
webmaster@sqlservercentral.com

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -