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

Dig Out the Root Cause

This editorial was originally published on Apr 28, 2015. It is being re-published as Steve is traveling.

Early in my career in technology, I worked as a system administrator on a Novell network. Periodically we'd have crashes of servers on our network, or application failures, and while we understood that sometimes these were caused by transient errors, we often invoked a root cause analysis process when an issue repeated itself. I'm sure that the environment in which we worked, a nuclear power plant, contributed to the idea that we should always understand why some system failed.

I was reminded of this while reading Grant Fritchey's "Understand the True Source of Problems" in which he relates a few "best practices" that are likely folklore stemming from ignorance rather than actual good ideas. I've seen a few of these rules at various places in the past, often implemented because they appeared to work. However, we need to remember this:

Correlation != causation

Just because you perform some action and observe an effect doesn't mean that one caused the other. If that were the case, I'd never install new hardware or applications on my computer systems as I've had crashes during various installations. However I often back out a change, or retry it and realize that I had a coincidental result, rather than a related one. The same thing has occurred in more complex systems where an action appears to cause an issue, but in reality, the two items are unrelated, or loosely related.

We often don't take the time to determine the root cause of many issues, which is disappointing. While it often doesn't seem to be a worthwhile use of resources, I bet that often we'd learn there are actions we are taking (or code we've written) that actually is the cause. If we learned from our mistakes and could avoid making the same ones again, we'd greatly improve the quality of our technology systems, with many fewer issues over years.

Unfortunately, "good enough" is often good enough, even if it does result in a bit of downtime.

Steve Jones - SSC Editor

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

Redgate Database Devops
 
 Featured Contents

Azure DWH part 20: Create External and Internal tables As Select

Daniel Calbimonte from SQLServerCentral.com

CTAS and CETAS are very important T-SQL features in ASDW. These features allow to create a table and fill with data based on a query.

Loading data into SQL Data Warehouse

Additional Articles from Redgate

In this step-by-step guide, we’ll be walking through the process of moving data from an on-premises SQL Server to Azure SQL Data Warehouse using the Copy Data feature in Azure Data Factory. The use case we’ll focus on is the first-time loading of data.

4 Ways to Move Data Into a Reporting Server

Additional Articles from Brent Ozar Unlimited Blog

You’ve decided that you need to offload reports to a different SQL Server, and you’re willing to pay the costs. Here are the most common ways to move the data from production to a reporting server, arranged roughly from easiest-to-implement to hardest.

From the SQL Server Central Blogs - Basic User Functions in R

Steve Jones - SSC Editor from The Voice of the DBA

As I’ve been learning more about the data platform, I’ve been exposed to some R language code. This makes sense, as more comprehensive data analysis needs something other than...

From the SQL Server Central Blogs - SQLSaturday Automatic Messages

Andy Warren from SQLAndy

For those who haven’t used the admin tools for SQLSaturday when an event is created there are a set of messages loaded automatically. It’s up the event admin if...

 

 Question of the Day

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

 

The CUME_DIST ranking

I have this code in SQL Server 2017:
WITH myTally(n)
AS
(SELECT n = ROW_NUMBER() OVER (ORDER BY (SELECT null))
 FROM (VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10)) a(n)
  CROSS JOIN (VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10)) b(n)
)
SELECT TOP 100 n
INTO Rank100
FROM myTally;
I want to execute this code to get the number and the CUME_DIST ranking.
SELECT n
, CUME_DIST() OVER (ORDER BY n) AS cd
 FROM dbo.Rank100
 ORDER BY n
What is the value returned for n = 10

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)

Getting the Options

What is returned by @@OPTIONS?

Answer: A bitmap of SET options

Explanation: This returns a bitmap of the SET options for a user connection. Ref: @@OPTIONS - https://docs.microsoft.com/en-us/sql/t-sql/functions/options-transact-sql?view=sql-server-2017

Discuss this question and answer on the forums

 

Featured Script

Stack multiple tables using UNION ALL

T::Libs from SQLServerCentral

Avoid conversion errors when using UNION to stack rows from multiple tables.

--SETUP
CREATE TABLE DBO.TABLE1 (NAME1 VARCHAR(100), NAME2 VARCHAR(100), NAME3 VArchar(100))
INSERT INTO TABLE1 ([NAME1], [NAME2], [NAME3])
VALUES('T1N1','T1N2','T1N3')
CREATE TABLE DBO.TABLE2 (NAME1 VARCHAR(100), NAME2 VARCHAR(100), NAME3 VArchar(100), NAME5 VARCHAR(100), NAME6 VArchar(100))
INSERT INTO TABLE2 ([NAME1], [NAME2], [NAME3], [NAME5], [NAME6])
VALUES('T2N1','T2N2','T2N3','T2N5','T2N6')
CREATE TABLE DBO.TABLE3 (NAME1 VARCHAR(100), NAME3 VARCHAR(100), NAME5 VArchar(100), NAME7 varchar(100))
INSERT INTO TABLE3 ([NAME1], [NAME3], [NAME5], [NAME7])
VALUES('T3N1','T3N3','T3N5','T3N7')
CREATE TABLE DBO.TABLE4 (NAME4 VARCHAR(100))
INSERT INTO TABLE4 ([NAME4])
VALUES('T4N4')
--END SETUP

BEGIN TRY
DROP TABLE #MAPPER
END TRY
BEGIN CATCH
PRINT '#MAPPER ALREADY DROPPED'
END CATCH

--STORE T TABLE LIST INTO A TEMP TABLE FOR CONSISTENCY
BEGIN TRY
DROP TABLE #TABLES
END TRY
BEGIN CATCH
PRINT '#TABLES ALREADY DROPPED'
END CATCH
SELECT
IIF(TID>1, 'UNION ALL','') AS UNION_ALL
,TABLE_NAME
INTO #TABLES
FROM
(
SELECT
TABLE_SCHEMA + '.' + TABLE_NAME AS TABLE_NAME, ROW_NUMBER() OVER (ORDER BY TABLE_NAME) AS TID
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'TABLE_'
GROUP BY TABLE_SCHEMA , TABLE_NAME
) AS A
--STORE THE COLUMNS INTO ANOTHER TEMP TABLE
;WITH _COLUMNS
AS
(
SELECT TABLE_SCHEMA + '.' + TABLE_NAME AS TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME LIKE 'TABLE_'
)
, _TABLE_COL
AS
(
SELECT TABLE_NAME, COLUMN_NAME
FROM
(
SELECT
COLUMN_NAME
--INTO #ALL_COLUMNS
FROM
_COLUMNS
GROUP BY COLUMN_NAME
) AS A,
--NOW ENUMERATE ALL TO CREATE TABLE/COLUMN COMBINATIONS FOR ALL POSSIBLE
(
SELECT
TABLE_NAME
FROM
#TABLES
) AS B
),
_MAPPER
AS
(
SELECT
TC.TABLE_NAME, TC.COLUMN_NAME, IIF(B.COLUMN_NAME IS NULL, ''''' AS [' + TC.COLUMN_NAME + ']', B.COLUMN_NAME) AS MAPPER
,ROW_NUMBER() OVER (PARTITION BY TC.TABLE_NAME ORDER BY TC.COLUMN_NAME) AS COLIDE
FROM
_TABLE_COL TC
LEFT JOIN
_COLUMNS AS B
ON TC.TABLE_NAME = B.TABLE_NAME AND TC.COLUMN_NAME = B.COLUMN_NAME
)
SELECT * INTO #MAPPER FROM _MAPPER

DECLARE @SC NVARCHAR(MAX) = '--BEGIN
'
SELECT @SC = @SC + '
' + UNION_ALL + ' ' + '
SELECT ''' + T.TABLE_NAME + ''' AS META_TABLE_NAME, ' + STUFF((SELECT ', ' + M.MAPPER FROM #MAPPER M WHERE M.TABLE_NAME = T.TABLE_NAME FOR XML PATH('')),1,1,'') + ' FROM ' + TABLE_NAME
FROM #TABLES T

PRINT @SC
EXEC SP_EXECUTESQL @SC

SELECT NAME1, NAME2, NAME3, '' AS [NAME4], '' AS [NAME5], '' AS [NAME6], '' AS [NAME7] FROM dbo.TABLE1
UNION ALL
SELECT NAME1, NAME2, NAME3, '' AS [NAME4], NAME5, NAME6, '' AS [NAME7] FROM dbo.TABLE2
UNION ALL
SELECT NAME1, '' AS [NAME2], NAME3, '' AS [NAME4], NAME5, '' AS [NAME6], NAME7 FROM dbo.TABLE3
UNION ALL
SELECT '' AS [NAME1], '' AS [NAME2], '' AS [NAME3], NAME4, '' AS [NAME5], '' AS [NAME6], '' AS [NAME7] FROM dbo.TABLE4

--GET COLUMNS
--CREATE ALL POSSIBLE COMBINATIONS
--COMARE WITH EXISTING COMBINATIONS
--REPLACE NON-EXISTENT COMBINATIONS WITH BLANK REPLACEMENT PLACEHOLDERS.

More »

 

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
Need connect string to connect from Linux to SQL Server using an A/D group name - ISO way to setup a connection string to connect from Linux to SQL Server using an A/D group name. (we do NOT want to use a SQL Login!) - this link details the setup for a Linux connection to a SQL Server database: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Linux - one of the final instructions during setup is to add […]
SQL Server 2017 - Development
How to split time into hourly slot using SQL (can use view,or stored proc or fun - I have data in table which has start date, end date and duration. I want to show hourly time slot. **logic**: - Condition 1. If start date =9:00 and end date = 11:00 then show the date as 09:00-10:00 10:00-11:00 It should repeat 2 times and all related column data will also repeat 2 times. […]
SQL Server 2016 - Administration
SQL Cluster - I am looking at a Cluster that has been built by a person that during the SQL Cluster installation he did not select all CSV's that related to the instance.  This has meant that the storage fails over independently which is not ideal.  there has been a case that two of the required volumes were […]
Admin puzzler - ok so Friday off I get a call from user doing  posting taking over an hour( should take 5 minutes).  No blocking do deadlock no high CPU.  Active sessions show higher reads than normal.  No open trans.  Go to mgmt. studio and when I try to open objects on main pharmacy database it times out.  […]
SQL Server 2016 - Development and T-SQL
Using @@ROWCOUNT To Return Second Recordset in Sproc - I'm working with a Stored Procedure that hopefully will return two recordsets to a Classic ASP application. Currently, when I test my Stored Procedure, @@ROWCOUNT always returns the count of 1, even when the count is not 1. Here is my code for the Stored Procedure (below). Would I need to return the @row variable […]
Problem to Display Field With OPENXML - Hello community, I am trying to Importing and Processing data from XML files into SQL Server tables, following the example post on this site : https://www.mssqltips.com/sqlservertip/2899/importing-and-processing-data-from-xml-files-into-sql-server-tables/ by Arshad Ali. This is the first time i use this technique, then i put only one filed to display, but i dont know why the result is always […]
Administration - SQL Server 2014
Auto Shrink on live DB - Hello, On one of our customers' live server there are both live and UAT DBs. The latter occasionally replicated from the live DB upon customer's request. All has been done and maintained by DBA's.  When such a copy generated I am normally required to truncate several of our biggest tables (some over 100 MBs), which […]
SQL Server 2005 Installation After 2014 as Default Instance on Win Server 2012 - Greetings! Did anyone notice the anomaly as in below screenshot? When tried to install SQL Server 2005(bare version 9.0 - No SP) after SQL Server 2014(version 12.0) is already installed, the SQL 2005 threw error showing SQL 2014 installation as SQL 2000. OS : Windows Server 2012 X64 SQL Server 2014: Developer X86 SQL Server […]
Development - SQL Server 2014
Stored Procedure with Parameters in Excel - Long Run time - I have a stored procedure with two date variables, Start date, End date. If I run this in excel, it takes forever and eventually deadlocks. ALTER PROCEDURE [dbo].[lost_sales_v2] @SD datetime, @ED datetime If I take the variables out of the procedure name and embed a set date range in the query, it returns in less […]
SQL 2012 - General
Using Correlated Queries with OPENQUERY - Good day everyone,   I'm new to this forum and was hoping I could get some help with what I'm trying to accomplish. I'm trying to delete old users from each respective database from a list I have. Now I'm using SQL Server 2012 to do this, but the databases i'm connecting to are in […]
SQL Server 2012 - T-SQL
Index Size Question - I'm trying to track down storage usage on our SQL Server 2012 instance.  I have a table with 11,703,018 rows and 10 indexes (9 non-clustered + PK) on it.  The PK is a clustered uniqueidentifier (I know not the greatest but i'm stuck with it for now) that only has the uniqueidentifier column included (size […]
Find time different based on Type by making group - I have data like attached picture, I want to make group each event when it starts from 1 and end till its max of eventId = 14 and calculate the time difference ... as shown in picture. If there are 8 EventType with 1 then it should have max of 8 eventType with EventType 14. […]
SQL Server 2008 - General
Unable to load text data in using BULK INsert with XML Format file - I have the following table   IF OBJECT_ID('[TempDB]..[#LoadData]') IS NOT NULL DROP TABLE [dbo].[#LoadData]; CREATE TABLE [dbo].[#LoadData] ( [RTOPartyID] INT NULL , [Prefix] NVARCHAR(255) NULL , [FirstNames] NVARCHAR(255) NULL , [LastName] NVARCHAR(255) NULL , [Suffix] NVARCHAR(255) NULL , [PartyType] NVARCHAR(255) NULL , [PlaceOfBirth] NVARCHAR(255) NULL , [TaxIdentificationNumber] NVARCHAR(50) NULL , [CrownServant] BIT NULL , [DateOfBirth] […]
Replication DB name - Hi, Supposing we would like to replicate a copy of a DB, called DB1 to another server. Does the database need to be called DB1 on the subscribers or does that not matter?
Powershell
Something akin to GROUP BY in SQL - So I have an array: $array = @() $Props = [ordered]@{Table="Table1"; Col1=1; Col2=2} $array += New-Object psobject -Property $Props $Props = [ordered]@{Table="Table2"; Col1=4; Col2=5} $array += New-Object psobject -Property $Props $Props = [ordered]@{Table="Table1"; Col1=3; Col2=7} $array += New-Object psobject -Property $Props $Props = [ordered]@{Table="Table2"; Col1=2; Col2=6} $array += New-Object psobject -Property $Props I want to […]
 

 

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

 

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