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

Daily Coping Tip

Ask a loved one what they feel grateful for at the moment

I also have a thread at SQLServerCentral dealing with coping mechanisms and resources. Feel free to participate.

For many of you out there working in a new way, I'm including a thought of the day on how to cope in this challenging time from The Action for Happiness Coping Calendar. My items will be on my blog, feel free to share yours.

Falling Over our Assumptions

This editorial was originally published on Apr 8, 2009. It is being re-run as Steve is on vacation.

Often, the mistakes that are made in SQL code seem to be so perverse that one is left scratching ones’ head and wondering whether there is a basic incorrect assumption underlying all the errors.

I think one of the most insidious assumptions is that each SQL Statement takes the same length of time to execute. It is crazy, I know, but we are talking about unconscious, impulsive judgments here.  When I’m taking to developers who are gridlocked with a complex routine, I always advise them to break the problem down into a number of simple testable steps; using temporary tables for intermediate results.  They hate it. Often, the problems have happened because they’ve gone headlong into an attempt to get a complex result in one SQL Statement.  ‘Why create so many statements when one will do? , they often say.

When I had less self-confidence as a SQL Programmer, I’d break problems down into simple steps, test each step for sanity, logic and performance, and then re-write them in as few statements as possible, using derived tables and subqueries. Nowadays I don’t always bother with the last step, because the contribution that this step makes to the performance of the entire process  is usually negligible. It just looks better.  I have my pride; well I used to.  The advantage of a series of simple steps is that it is easier to test, to maintain, and to understand.  The disadvantage is that many developers will whistle through their teeth and say ‘Cor, I bet that runs slow!’, and try to rewrite it in one statement.

We all approach our development work armed with poorly tested assumptions, and a lot of the excitement of the job is in testing them and finding them wrong. However, if you keep them for too long, you’ll soon find that they get in the way of the quality of your output.

So what other assumptions do we fall over?  Bearing in mind General Sedgewick's fatal assumption, "Why, my man, I am ashamed of you, dodging that way,  They couldn't hit an elephant at this distance.",  here are a few assumptions that can cause a lot of subsequent problems

    • 'My routine will scale in a linear fashion'
    • 'If I test this in a single-user database, it is likely to work in a multi-user one.'
    • 'It is always quicker and easier  to do stuff in C#'
    • 'I can always shave time by denormalising'
    • 'Joins cause performance problems'
    • 'get something up and running. We can always tidy it up later'

Come across any other fatal assumptions recently in the office? It would be great to hear them.

Phil Factor

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

 
  Featured Contents

Logshipping to SQL Server on Linux

Evgeny Garaev from SQLServerCentral.com

An example of a database migration from SQL Server 2016 on Windows to MS SQL Server 2017 on Linux.

Storage 101: Convergence and Composability

Additional Articles from SimpleTalk

In this article in the storage series, Robert Sheldon explains infrastructure options that simplify administration and improve resource utilization. He discusses the differences and benefits of converged, hyperconverged, and composable infrastructures.

From the SQL Server Central Blogs - New Management Hub in Azure Data Factory

Koen Verbeeck from Koen Verbeeck

I wanted to manually start an Azure-SSIS Integration Runtime in ADF, so I went to the edit section and then to connections. But instead of showing me my linked...

From the SQL Server Central Blogs - Creating a Repository from VSCode–#SQLNewBlogger

Steve Jones - SSC Editor from The Voice of the DBA

I’ve been working with a few different git clients, and trying to write some articles to help people get started. As I do this, I thought it was interesting...

 

  Question of the Day

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

 

Getting the default language

How do you programmatically get the default language for a SQL Server instance?

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)

More Means in R

I have a dataframe in R, with a number of columns in it. This was created from a csv file.

sales <- read.csv2(file="d:\\downloads\\sales_data.csv", sep=",")

I run this code with the colmeans() function:

colMeans(sales[sapply(sales, is.numeric)])

What does this do?

Answer: Calculates the mean of all numeric columns

Explanation: This calculates the mean for all numeric columns, but applying the is.numeric function to all  columns and returning a list of those columns to colmeans(). 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
SSMS: How to save multiple resultsets from same query into 1 result or 1 file? - I am submitting an official request for DBA of certain servers to run a script on those servers and give me back the resultset. However the script (the actual script is 3 times larger than the attached and returns 20 more results) returns multiple results, so a DBA will not be copy/pasting each resultset into […]
Availability Groups for failover AND mirror - I've got a 2-node failover AG setup. I want to add a 3rd node to be used as a reporting server. That could be read-only, but has to be available all the time. For reasons beyond my control, I can't use replication. The database has no primary keys indexes (3rd-party software design). So, it all […]
SQL Server 2017 - Development
Ignoring error and continue - Hi, I am writing a Stored Procedure to update a table in multiple databases. In some on the databases that table doesnot exist. So, I want to ignore the error and continue to next database update. I also want to stop showing error at all while executing the Stored Procedure. So, please help to ignore […]
SQL Server 2016 - Administration
Query Store regressing queries Report: can I get its results without GUI? - The GUI is beautiful and all. Yet only Sr. Prod DBAs can access that, noone else, in our environment. Can I request them to send me that report in any other format than visual/direct access via GUI?  How? is there a ready script for something like that somewhere by any chance? Thank you.
Reading Extended Events File...Suggestions ? - Per another thread, I created an Extended Event to capture SQL activity. But now I want to read the file and find specific event. I ran "SP_WHO2", then wanted to find it. I found this code. select * from sys.fn_xe_file_target_read_file('D:\SQL Server 2016 SP2\TraceFiles\SQL_Activity_EE_0_132368306610620000.xel', null, null, null) where event_data like '%sp_who2%'   For some reason I […]
Creating DB diagram - Hi, I was planning to create a DB diagram of a user DB to better understand the relationship however when I right-click on database diagram (please expand the user DB to see this option) I see an alert window saying 'This database does not have one or more of the support objects required to use […]
SQL Server 2016 - Development and T-SQL
Help with T-SQL - I have a web interface for managing tool rentals for our chapter members. I have a display page that will list all of the tools we have and to flag those tools that are currently being rented out to include the expected return date. The important thing is to know which are available and which […]
Administration - SQL Server 2014
CDC locking tables? - Hi We enabled CDC for a few tables in a Dynamics AX database and immediately some AX batch jobs got stuck in deadlock. After disabling CDC, the batch jobs continued to run. So, does CDC take an exlusive lock for a table when you enable it? Another hypothesis is that CDC slowed down the batch […]
SQL Server 2012 - T-SQL
How to sperate an address without spces - Hi, I have address in a database table like this below and should got to -->: 1627W.PINNA   --- > 1627 W. PINNA 3000CLARCONAROADLOT252   --> 3000 CLARCONA ROAD LOT 252 2633COURTLANDBLVD  --> 2633 COURTLAND BLVD 7113RDAVESOUTH --> 7113 DAVE SOUTH 1123Main Street If this was one I could do this: Declare @S varchar(20) = […]
? ON Parsing an XML Field - Hi, I know I've asked this before and got a good link , but can't figure out how to parse this XML field. I would usually parse something like Data.Value('Data/.../..) But not sure how to parse out say "Case" from the field below(SqlParameters)?
SQL Server 2019 - Administration
SQL server DBA certification - Hi As a long time Oracle DBA who recently started working on SQL server, I am looking into getting SQL server certification for DBAs; this is also the request from my manager. I web searched and hit this one: https://www.microsoft.com/en-us/learning/exam-list.aspx but I am unable to find an Administration test, not for newer versions of SS […]
SQL Server 2019 - Development
Script specific stored procedures - Dear All, I have a database which has about 50000 stored procedures. I need to script out around 200 procedures from the database. Using SSMS i am finding difficult to go and search for the object name one by one and generate the script. Is there a way to script out n number of objects […]
Need Help to calculate time difference in same column in sql - I have employee login date and time from the login date and time i need calculate log out date and time. In a day employee login first time as some activity and next time he's login in different activity so that i need to calculate middle time so that will be logout time for that […]
Integration Services
SSISDB Execution History - Vanished! - Morning Guys, Does the execution history of an SSIS package/project get truncated when that project is redeployed? I've recently had to debug a package that was redeployed yesterday and its history has vanished. My SSIS knoweldge is small, so I'm not sure -- this package runs daily, and we have version history for packages configured […]
COVID-19 Pandemic
Daily Coping 17 Jun 2020 - Today’s tip is to take a photo of something that brings you joy and share it. http://voiceofthedba.com/2020/06/17/daily-coping-17-jun-2020/
 

 

RSS FeedTwitter

This email has been sent to newsletter@newslettercollector.com. 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

 

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