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

Daily Coping Tip

Today link your decisions and choices to your purpose in life

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.

Crack that Encrypted Data

This editorial was originally published on Apr 19, 2016, and is being re-run today as Steve is on vacation. It's still relevant, and ransomware remains a problem.

Ransomware appears to be gaining some traction as a new trend. For awhile in my career, it was virus programs designed to send to all your contacts. Then it was infections to use your computer as part of a bot net. Now it's encrypting your files and demanding a payment to get the password.

I'm starting to think that a)I need to ensure I have solid, better backups on all devices, and b) I should pay attention and be aware of decryption programs. I'd love to say that I could build a decryption program, like someone did, but as much as I'm interesting in encryption and study it, that's a little out of my skillset wheelhouse.

I'm actually starting to think that this might be a way that people in communities, like the SQL Server community, can help each other. We can be aware of potential ransomware threats, like the one that hit this hospital, and potentially share ways to recover from the incident, or even decrypt the drives. In fact, I suspect it might be worth keeping a system handy to practice decryption techniques, if you can determine the attack vector.

I'm sure many organizations wouldn't want to share details of attacks and infections, but this is exactly the type of information that we, as data professionals, should be sharing. It's incredibly difficult to keep up with all the threats and attacks, not to mention the techniques to recover systems. I'd urge all of you to ask your employers if you can at least help others, even if you can't disclose how or where you gained the knowledge. If nothing else, the information needs to be shared more publicly to allow us to better protect our systems and be effective custodians of data.

Steve Jones - SSC Editor

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

 
 Featured Contents

Azure DWH part 19: Backup and Restore SSAS

Daniel Calbimonte from SQLServerCentral.com

In the part 18, we created a Cube based on the Azure Data Warehouse. In this new chapter, we will work with the cube, create backups and show some tips to restore.

Updated First Responder Kit and Consultant Toolkit for May 2020

Additional Articles from SQLServerCentral

My favorite new things are that sp_BlitzIndex @Mode = 2 now makes it even easier to do disconnected index tuning just purely inside a spreadsheet, and sp_BlitzCache runs faster on big servers.

From the SQL Server Central Blogs - T-SQL Tuesday #126 – Folding@Home and 3D Printing

Tim Radney from Tim Radney - Database Professional

This month’s T-SQL Tuesday is hosted by my friend Glenn Berry. Glenn invites us to write about what we have been doing as a response to COVID-19. Glenn shared...

From the SQL Server Central Blogs - Weird Docker Desktop Issues – Unable to Create Hyper-V VM

Steve Jones - SSC Editor from The Voice of the DBA

I was setting up my new machine the other day and one of the first things I did was get Docker Desktop. I grabbed this and enabled Hyper-V at...

 

 Question of the Day

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

 

The Countrows Result

I have two tables that are related in a Power BI model as a parent and child. For ID 1, there are 3 rows in the child table with the matching key column value. For ID 6, there are no rows in the child table. If I define a column in the parent table like this:
SOME ROWS = COUNTROWS(RELATEDTABLE(OrderLine))
where OrderLine is the child table, what value is returned for ID 6?

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

 

 

 Yesterday's Question of the Day (by Greg Larsen)

Inlining Scalar UDFs

Scalar user defined functions (UDFs) can cause performance issues that can often be difficult to troubleshoot. Microsoft introduced a new 2019 feature called T-SQL Scalar UDF Inlining that can improve performance of some of these functions without changing any of your code. Which of the functions can take advantage of this feature? (choose 3)

--Function 1
CREATE OR ALTER FUNCTION dbo.GetRating_1(@CustomerID INT) 
RETURNS VARCHAR(20) 
AS 
BEGIN 
DECLARE @Rating VARCHAR(20);
SELECT @Rating = Rating 
FROM Customer 
WHERE CustomerID = @CustomerID;

RETURN @Rating;
END
GO

CREATE OR ALTER FUNCTION dbo.GetRating_2(@CustomerID INT) 
RETURNS VARCHAR(20) 
AS 
BEGIN 
DECLARE @Rating varchar(20);
IF @CustomerID % 4 = 0 BEGIN 
SET @Rating = 'Diamond';
END
ELSE IF @CustomerID % 4 = 1 BEGIN
SET @Rating = 'Gold';
END
ELSE IF @CustomerID % 4 = 2 BEGIN 
SET @Rating = 'Silver';
END
ELSE IF @CustomerID % 4 = 3 BEGIN 
SET @Rating = 'Bronze';
END

RETURN @Rating;
END

GO

--Function 3
CREATE OR ALTER FUNCTION dbo.GetRating_3(@CustomerID INT) 
RETURNS VARCHAR(20) 
AS 
BEGIN 
DECLARE @Rating varchar(20);
DECLARE @RatingID INT;

SELECT @RatingID = RatingID 
FROM Customer
WHERE CustomerID = @CustomerID;

IF @RatingID = 0 BEGIN 
SET @Rating = 'Diamond';
END
ELSE IF @RatingID = 1 BEGIN
SET @Rating = 'Gold';
END
ELSE IF @RatingID = 2 BEGIN 
SET @Rating = 'Silver';
END
ELSE IF @RatingID = 3 BEGIN 
SET @Rating = 'Bronze';
END

RETURN @Rating;
END


GO

--Function 4
CREATE OR ALTER FUNCTION dbo.GetRating_4(@CustomerID INT)
RETURNS VARCHAR(20)
AS
BEGIN
   DECLARE @Ratings TABLE(RatingID INT, RatingDesc  varchar(20));
   DECLARE @Rating VARCHAR(20);

   INSERT INTO @Ratings(RatingID, RatingDesc)
   SELECT RatingID, RatingDesc
   FROM Rating;

   SELECT @Rating = R.RatingDesc
   FROM Customer  AS C
   JOIN @Ratings  AS R ON C.RatingID = R.RatingID
   WHERE CustomerID = @CustomerID;

   RETURN @Rating;

END

GO

--Function 5
CREATE OR ALTER FUNCTION dbo.GetRating_5(@RatingID INT) 
RETURNS VARCHAR(20) 
AS 
BEGIN 

DECLARE @ID INT = 0;
DECLARE @Rating varchar(20);

WHILE @ID <> @RatingID BEGIN 
SET @ID = @ID + 1;
END;

SELECT @Rating = RatingDesc 
FROM Rating 
WHERE RatingID = @ID;

RETURN @Rating;
END

 

 

 

 

 

Answer: Function 1, Function 2, Function 3

Explanation: The functions found in answers a, b, and c take advantage of inlining. It doesn’t work when you have a loop or a table variable in the function. You can also use the is_inlineable column of sys.sql_module DMV to find out.

SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, sm.is_inlineable
FROM sys.sql_modules AS sm 
JOIN sys.objects AS o ON sm.object_id = o.object_id 
WHERE o.type_desc = 'SQL_SCALAR_FUNCTION';

Reference:

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
Old, unnecessary SQL Server windows updates keep failing - any ideas? - Background My organization tightly controls what’s on our internal windows update server. The version of SQL Server that I have installed is Microsoft SQL Server 2017 (RTM-CU20) (KB4541283) - 14.0.3294.2 (X64)   Mar 13 2020 14:53:45   Copyright (C) 2017 Microsoft Corporation  Developer Edition (64-bit) on Windows 10 Enterprise 10.0 (Build 17134: ) (Hypervisor) For some […]
One of six 2017 instances offline - Always On. - Did patch Tuesday yesterday across 6 UCS blades. Servers are 2019 datacenter in a cluster. Each blade has 4 instances so 4 availability groups of 6 members each. One of the 2017 instances is in a bad state. I've tried a repair, I've tried removing updates (even though the other 5 prod blades are fine, […]
SQL 2017 AGL - only accessible locally - Hi, I've got 2 x SQL 2017 CU20 (Dev edition) boxes in a Windows cluster with an AG and listener (non readable sync secondary). The DBs are synchronised and the AGL is contactable through SSMS on the primary server when I'm RDPd on. The SPN is set up for the AGL name with the SQL […]
SQL Server 2017 - Development
Bulk Insert & link relationship between inserted row - Hi, Let me elaborate with example:- I having an existing TableA with below sample column & data Date                             Amount                 Category               Name 2018-01-01                […]
SQL Server 2016 - Development and T-SQL
CTE left join not giving me correct result - Hello, Why is the Left Join with a CTE giving me wrong results? I want to know which Emails are not in Table B using their UserIDs Instead it's giving me all the records from CTE and Null values from the Table B. What am I doing wrong? Many thanks. ; With CTE as ( […]
Encryption table and saving in 2016 - Hi, How would you encrypt data from multiple tables and save in a temp tables using a script (tsql)? please share general logic in sql 2016 version. Should we use always on encryption? or something else and then also how do you decrypt the data from the same temp table and save those in the […]
SQL Server 2019 - Administration
Queries run by a particular login or Database user in SQL Server 2016 - Hello, Is there a way in SQL Server to find out which queries were run by particular login in SQL Server and on which databases? If somebody can provide a script, that will be great. Thanks in advance
Trouble installing latest version of SSMS - Last night I went to the control panel and removed any programs that had 'SQL' in its name.  That was the 2017 version of SSMS.  I wanted to start fresh.  I downloaded SSMS 18.  I'm not sure of the server name, so I tried to find it here: https://docs.microsoft.com/en-us/sql/ssms/tutorials/ssms-tricks?view=sql-server-ver15#find-the-error-log-location-if-you-cant-connect-to-sql-server under the section titled "Find the […]
SQL Server 2019 - Development
Function issue with union (two databases) - I want this function to  retrieve the latest buyer from two databases db1 and db2. It worked for a single db.    Now I try to use UNION to query both dbs an get the latest of the two It won't accept this function "Select statements included within a function cannot return data to a […]
Export sql results to csv -   Hi all, Hopefully you can help me. I have created a sql job which returns some results and then exports it to a csv file. But each column is merged into one cell. The way I have done this is using the sqlcmd feature as per the below: sqlcmd -i Is there […]
How to use stored procedure result set into a script task in SSIS - Hello, guys! I created a SSIS package in Visual Studio Community 2019: Everything is working fine, but I don't know how to pass the data from "Commutations" (SQL Task) to "Net Present Value" (Script Task). Basically, "Commutations" generates a result set that I'm passing to a SSIS object variable. This result set has a couple […]
Pivot Table Problem - I am having a huge brain fart on how to accomplish what I want. I want to pivot the attached set of data (sql file) to look like this (I know its an image but I am not savy enough to plop an actual result set in here). The attached file creates a temp file […]
Integration Services
Execute Powershell Script from Script Task - Has anyone managed to execute a PoSh script from within a Script Task? When I started looking at this, it seemed like it would be straightforward enough and the process is described here. But ... the DLL which that article refers to (and which appears to be necessary to execute PoSh from C#) is called […]
COVID-19 Pandemic
Daily Coping 21 May 2020 - Today’s tip is to reflect on what makes you feel really valued and appreciated. My thoughts: http://voiceofthedba.com/2020/05/22/daily-coping-22-may-2020/
Daily Coping 20 May 2020 - Today’s tip is: Hand-write a note to someone you love and send them a photo of it. http://voiceofthedba.com/2020/05/20/daily-coping-20-may-2020/
 

 

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

 

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