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

Documenting with Tests

This editorial was originally published on 14 May 2015. It is being re-published as Steve is at a SQL in the City Summit.

Documenting code isn't a task that many people enjoy. Those of you that have been through a computer science curriculum probably added lots of verbose, and obvious, comments to code. It's probably unlikely that you ever found much value in the comments in a paying job.

There are all sorts of ideas on how to document your softwarewriting good comments, and even refactoring code to remove unnecessary comments. I'm sure that if we put five developers in a room, we'd end up with eight different ways to comment code that would be debated, with no agreement on how to proceed.

I ran across an interesting approach from Ed Elliot on documenting your code with unit tests. I hadn't thought about the tests providing some documentation, but it's an interesting idea. I'd have to work with the concept a bit, but I'm skeptical I'd get enough information from unit tests to ensure I understood what a stored procedure was doing, especially if I had 10 tests for a long procedure.

I do think unit tests are important, and perhaps in conjunction with some type of code header that gives the requirements the procedure fulfills, I'll get enough information to understand the code.

I don't have a universal solution that I think will work in most situations, but I do think that having a tool like intellisense or SQL Prompt helps you self document code with expressive names for columns, variables, and aliases. If nothing else, those phrases for variables can clue the next programmer in to what is happening better than single letter names.

Steve Jones - SSC Editor

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

Redgate SQL Monitor
 
 Featured Contents

Real-time moving averages for IoT with R

nick.dale.burns from SQLServerCentral.com

Computing an average over all your data is easy, but what if your data arrives incrementally and you need to be able to compute real-time averages on the fly? That's what we are going to look at.

Database Build Blockers: Cross-Server Database Dependencies

Additional Articles from Redgate

Phil Factor demonstrates how to tackle builds when databases make cross-server references. The technique uses synonyms to represent the remote objects, and local 'stub' objects to overcome the problems caused by 'missing references' when building the individual objects.

Entity Framework Core Raw SQL Queries Examples

Additional Articles from MSSQLTips.com

In this article we look at how to run SQL Server queries with Entity Framework Core using the DbSet.FromSql method, parameterized queries, stored procedures and using the Database.ExecuteSqlCommand property.

From the SQL Server Central Blogs - Using SQL Dependency Tracker as a Picklist

Steve Jones - SSC Editor from The Voice of the DBA

This is part of a demo series I did for a customer workshop. I’m adding a little more detail and explanation of the demos of products I gave. A...

From the SQL Server Central Blogs - Memory Settings for Running SQL Server in Kubernetes

aen from Anthony Nocentino's Blog

People often ask me what’s the number one thing to look out for when running SQL Server on Kubernetes…the answer is memory settings. In this post, we’re going to...

 

 Question of the Day

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

 

Spark

SQL Server 2019 will integrate with Spark. What is Spark?

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)

MAX() and MAXX()

What's the difference between the MAX() and MAXX() functions in DAX?

Answer: The MAX() returns the largest value in a column while MAXX() returns the largest value from an expression run on the column

Explanation: The DAX MAX() function "returns the largest numeric value in a column." The DAX MAXX() function "evaluates an expression for each row of a table and returns the largest numeric value. 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 2017 - Administration
memory available but excessive workfiles still created - I'm analyzing PAL results during a period of poor performance and finding warnings of excessive "Workfiles Created/sec."  My understanding is that these workfiles are created when data being processed is too big to fit into memory and spilled to disk.  But MSSQL is only using 30GB of the 59GB max it is allocated, and the […]
Auditing selective users - Hi, I am putting together sql server auditing for a certain project. I create a sql server audit object (which writes audits to file). Then I create a database audit specification. First I used public as principal CREATE DATABASE AUDIT specification [DBAuditSpec] FOR SERVER AUDIT [DBAudit] ADD (SELECT, INSERT, UPDATE, DELETE, EXECUTE, RECEIVE, REFERENCES ON […]
Create index ... online=ON - Why is this INDEX setting not persistent ?  I'm testing this on SQL2019, but I've seen the same thing on SQL2016. I run this CREATE NONCLUSTERED INDEX [ImageActID] ON [dbo].[Image]( [ImgID] ASC )WITH (SORT_IN_TEMPDB=OFF, DROP_EXISTING=ON, ONLINE=ON, ALLOW_ROW_LOCKS=ON, ALLOW_PAGE_LOCKS=ON) ON [PRIMARY] GO Then I refresh and right click on the index and select "Script index as […]
SQL Server 2017 - Development
simple insert statement issues - Hello, create table #temp2(datename datetime, lastprocessed datetime DEFAULT'getdate()' NULL) insert into #temp2(datename) select distinct convert(date, c.ActualDate, 101) AS [DateName] from dim.calendar c select * from #temp2 I get below error when I run above Msg 241, Level 16, State 1, Line 20 Conversion failed when converting date and/or time from character string.
SQL Server 2016 - Administration
Adding 3 rd node in Alwayson - Hi, We have 2 node Alwayson setup. Planning to add 3rd node. To add 3rd node, do we need to remove databases from AG and re-configure them from scratch after adding 3rd node?
SQL Server 2016 - Development and T-SQL
Recommended Reading? Statements, batches, control-of-flow - When trying to create / save / execute a single .sql file containing multiple DDL operations, such as: use database go create procedure [procname]() as begin ------------------ end go use database go create view [viewname] as use database go create anotherview [viewname2] as ..............ETC and getting errors such as "Create View must be the only […]
Deduplicating records from monthly table backups? -   I have a database that has monthly backups of a table for the past five years... i.e., they copied the table at the end of the month to a table called theHugeTable_mm_yyyy.  Now as you can imagine, tables are huge... and the majority of the table data didn't change from one month to the […]
@@TRANCOUNT - The question is:  What is @@trancount after this SP is executed?  I don't understand why the answer is 1. My understanding is for every BEGIN TRAN, @@TRANCOUNT is incremented by 1 and for every COMMIT, @@TRANCOUNT is decremented by 1, so why is the answer not 0? I know it has to do with the […]
Administration - SQL Server 2014
Upgrading from SQL 2008R2 SP1 to SQL 2014. - Hi guys, I'm planning to perform an upgrade on my current SQL server 2008R2 SP 1 to SQL Server 2014. Based on my current license limitation 2014 is the max I can go. I read KB by Microsoft, I need to be on at least SP2 for the upgrade to be successful (https://docs.microsoft.com/en-au/sql/database-engine/install-windows/supported-version-and-edition-upgrades?view=sql-server-2014) if this […]
Development - SQL Server 2014
Guaranteed Varchar to Date conversion - I regularly load in multiple files using SSIS into a staging table and then onto another table (I call them trans as they are never fixed).   The data goes into stage as it comes out of the file or other source. This way I can always prove I took in what I was supplied. Stage_policy […]
SQL 2012 - General
BUY 100% GRADE AAA+ COUNTERFEIT MONEY whatsapp::+13232503649 - We are the best and Unique producer of HIGH QUALITY Undetectable counterfeit notes and fake documents. With over a Trillion of our products circulating around the Globe. We offer only original high-quality counterfeit currency NOTES and fake documents which can be used anywhere ,anytime .These notes are of the highest quality. Korean made notes often […]
SQL Server Newbies
* to 1 - Can I replace the * with 1 here in the below code. Will it impact the result. IF EXISTS (SELECT * FROM dbo.tbTest where Test_ID = @Test_ID)  -- Like change to SELECT 1
Azure Machine Learning
Why no posts? - I've heard Microsoft promote their concept of the "modern data warehouse" and their tools to support machine learning.  In my mind, there are at least 2 big components embedded in what they say: marketing to promote adoption of their cloud services and genuine opportunities to add value to the community. When I hear the word […]
Integration Services
Automate the SSIS package to take Start and enddate - I have a master/parent package, that calls the child packages in SSIS. The Master package takes the startdate and enddate and get all the dates from the given Startdate and enddate and run the child packages in loop. Example: Startdate = 1/1/2019' and Enddate ='1/10/2019'. SO the Master loops through 9 times meaning 1-9th january […]
PowerPivot
Power BI Data Gateway - Azure VM v On-Premises - When you have a SQL Server instance running in an Azure VM and you want to connect Power Bi Data Gateway to it, do you install the Data Gateway or is there another way for Power BI to get the data, considering it isn't technically "On Premises"?
 

 

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

 

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