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

Daily Coping Tip

Find a caring calming phrase to say to yourself when feeling low

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.

The New Normal Annoyances

Recently I re-ran an old editorial on annoyances. The world of work has changed for many of us. For the last few months, many of us have previously worked in offices have had to work at home. We often have partners, roommates, spouses, kids, pets, and more that distract us from the environment we're used to being in while working on the data platform.

I don't know how the world of work will change, but I do know it will. As I write this, I'm not sure when I'll actually be able to go back to an office to work. While I don't go often, I am looking forward to spending a few days here and there with others when I'm able. What I'm not sure about is whether I'll see lots of people or just a few. Will there be rotations of who's in the office during the week? Will I, as an outsider, be able to meet with the large variety of developers I'm used to seeing, or am I an infection vector to be avoided?

I suspect that world of remote work will grow for many data professionals. It's been years since I needed to touch a physical server, and with the changes I've seen in many environments, it might not be quite as critical for many of us to show up and meet in a room every week. At the same time, I do think we've lost some of the ability to easily collaborate and coordinate our thoughts while we're remote.

Now that we've had a few months of a different way of working, I wonder if you have any new annoyances that bother you. For me, having more people at home has been a bit of a challenge as noise is a problem at times. It's not bad, but it's different than it was in 2019.

I'll also say that while meetings seem to be starting on time more often, I find we still have plenty of audio issues, and sometimes video issues. I also find that it's hard to decide when to talk and when I want to avoid interrupting someone. It seems that we have different delays in hearing each other at times, so we end up with a bit of a talking collision. Overall, however, I'm impressed and surprised at just how smoothly things are going.

I'm sure many of you are finding new challenges at home. Some from virtual school, perhaps some frustration still from your setup at home, or maybe there's something else. A few of you might not like the remote meetings and still not be used to them. I think that no matter how you feel, many of us are still going to need to adjust the way we work and learn to cope with our new annoyances for awhile.

Steve Jones - SSC Editor

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

Redgate SQL Prompt
 
  Featured Contents

Dear Past Me on My First Day as a DBA

Pam Mooney from SQLServerCentral

A letter to a past self from Pamela Mooney that might help a more junior DBA get up to speed quicker.

Data Masker with SQL Data Catalog Integration Automates Data Protection Process

Additional Articles from Redgate

Data Masker for SQL Server now integrates with SQL Data Catalog (seamlessly with our new GUI) to let you fully automate your data privacy and protection process, from data classification through to masking.

Explaining SQL Server Statistics with Playing Cards

Additional Articles from Brent Ozar Unlimited Blog

When you run a query, how does SQL Server estimate the number of rows? I’ll explain in this half-hour video demo using playing cards, then showing the same issues in SQL Server Management Studio.

From the SQL Server Central Blogs - Failing SQL Agent Jobs – Part 3

gbargsley from GarryBargsley

It is Tuesday!!  Time for Part 3 in the series about SQL Server Agent Job Failures. This installment will show you how to setup SQL Agent Alerts and Operators...

From the SQL Server Central Blogs - Adding ApplicationIntent=readonly to SQL Data Compare

Steve Jones - SSC Editor from The Voice of the DBA

Recently someone asked a good question about SQL Data Compare. How can they add applicationintent to the connection? If you are using Data Compare, and you are reading from...

 

  Question of the Day

Today's question (by Sergiy):

 

How Many Distinct Records

You have a table containing non-unique records:
CREATE TABLE #QOD ( Number int NOT NULL, String varchar(50) NOT NULL ) INSERT INTO #QOD (Number, String) SELECT 10, 'abcdefg' union all select 20, 'abcdefg' union all select 20, 'abcdefg'
How many records are returned by each of the following queries?
--Query1 select distinct NEWID(), Number, String FROM #QOD; --Query2 select NEWID(), Number, String FROM #QOD GROUP BY Number, String;

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)

How Many Rows Remain?

I have written this code.

DECLARE @founders TABLE (foundername VARCHAR(50)); BEGIN TRAN; INSERT @founders VALUES ('Andy'); INSERT @founders VALUES ('Brian'); INSERT @founders VALUES ('Steve'); ROLLBACK; SELECT * FROM @founders AS f;

How many rows are returned from the SELECT?

Answer: 3

Explanation: There are 3 rows returned. Table variables are not part of the transaction space.  This is one good technique for use with logging applications, as you can capture information about a transaction and access it in a CATCH or outside of a rollback. I haven't written a question like this in a long time, but was amused seeing it from Brent Ozar on Twitter and the range of responses. Ref:

Discuss this question and answer on the forums

 

Featured Script

Searching for orphaned DB files on the SQL server

martin.tydor@gmail.com from SQLServerCentral

See how to find those files that are not in use, but are taking up space on your instance.

##############################################################################################################
# Author: Martin Tydor
# Create date: 17/09/2020
# Description: PowerShell script for finding unnecessary DB files across the server drives.
# The result is the list of commands for removing the files which should be checked and
# executed in new PowerShell window.
#
# Prerequisities:
# SQL server permissions for the listing DB files and Read/Delete permission on Filesystem is required.
#
# !!!Warning!!!
#
# List can contain DB files stored on the server by some purpose and should be checked before execution!
# Files you want to leave on the server should be removed from the list!
# The script will not work on SQL server with more than one SQL server instance!
# Execute script on your own risk and responsibility!
##############################################################################################################

#configuration part
$SQLServerPort = '1433' #SQL server port
[string[]]$Includes = @('*.MDF', '*.NDF', '*.LDF') #Filetypes wich should be found
$Drives ='[C]' #Exclude drives, e.g. [CDMP] - server will not look for files on that drives

#clear screen
cls

#getting data from DB
try {
#Set datasource
$dataSource = [System.Net.Dns]::GetHostByName($env:computerName).HostName+','+$SQLServerPort
Write-Host "SQL server datasource: $dataSource" -ForegroundColor green
#Get DB files from SQL server
$connectionString = “Server=$dataSource;Database=Master;Integrated Security=True;”
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString

$connection.Open()
$resultsDataTable = New-Object System.Data.DataTable
$command = $connection.CreateCommand()
$query = “Create Table #temp (physical_name nvarchar(260));
Exec sp_msforeachdb 'Use [?]; Insert Into #temp (physical_name) Select physical_name From sys.database_files';
Insert Into #temp (physical_name)
SELECT mf.physical_name FROM sys.databases db INNER JOIN sys.master_files mf ON db.database_id = mf.database_id
except
select physical_name from #temp;
Select * From #temp
drop table #temp”
$command.CommandText = $query

$result = $command.ExecuteReader()
$resultsDataTable.Load($result)

$DBFilesArray = @()
foreach ($Row in $resultsDataTable.Rows){$DBFilesArray += @(,$($Row[0]).ToString())}

$result.Dispose()
$resultsDataTable.Dispose()
$connection.Close()
}
catch {
Write-Host "An error occurred:"
Write-Host $_
Break
}

#search DB files on file system
$files = get-psdrive -PSProvider "FileSystem" | Where-Object { $_.Name -notmatch $Drives} `
| % {get-childitem $_.Root -include $Includes –force -Recurse -ErrorAction SilentlyContinue | Where-Object { $_ -notin $DBFilesArray } } `
| Sort-Object -Property FullName

#write count of all found files
Write-Host "Total unused DB files: $($files.Count)" -ForegroundColor green
Write-Host "Copy rows with files you want to remove and execute them in new PowerShell window" -ForegroundColor yellow
Write-Host "*******************************************************************************************"

#write found files
foreach ($file in $files) {
Write-host "Remove-Item `"$file`" " -nonewline
Write-host "#$($file.Length) bytes" -foreground yellow
Write-host "#Updated:$($file.LastWriteTime)" -foreground yellow
}

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
DEA - What is the use of DEA tool in sql ?  how can we  install on sql ?
SQL 2017 MLS - cant add new python packages - Hi I'm new-ish to MLS and have been trying to add new python packages like  attrs  to the python but it hasn't been working. Our set up is SQL 2017 with CU14 on Win 2016. Python version is 3.5.2 The usual command I run is : "pip install attrs" ( without quotes ) and I […]
Index Fragmentation - I am looking into fragmentation in one of my databases and ran across these stats - should I be rebuilding these indexes? That's what it looks like, just want some ideas/confirmation to see if I'm on the right track.  
SQL Server 2016 - Administration
SQL Server 2016 seeding automatic stuck - Hi all, Problem help please, I have 2 servers in sql server 2016 and i have started seeding databases to the DR server within the GUI of AOG which is FCI  problem is that  one of my dbs which is 2 TB with take 1 month to finish. I need to stop this and continue […]
will this get replicated to secondary replica - Dear Experts, In Availability Group, if we move ndf file to another drive on primary, will this get replicated to secondary replica
SQL Server 2016 - Development and T-SQL
SQL Query - FULL JOIN multiple tables but return NULL results - Good day! Need help with my sql query code; first FULL JOIN "ILEtransfer" no NULL result but im getting NULL result once i add a FULL JOIN "ILEmsales" Thank you in advance! here's my sql query code; ;WITH Barcodes AS ( SELECT [BBI$Barcodes].[Item No_] ,[BBI$Barcodes].[Description] ,[BBI$Barcodes].[Variant Code] FROM [BBI$Barcodes] ), ILEtransfer AS ( SELECT [BBI$Item […]
Administration - SQL Server 2014
Server local connection provider has stopped listening - Hello, Once / twice a week I'm getting the following error. Server local connection provider has stopped listening on [ \\.\pipe\SQLLocal\MSSQLSERVER ] due to a failure. Error: 0xe8, state: 4. The server will automatically attempt to re-establish listening. where should I search for the source of the error? Is this error is due to the […]
Development - SQL Server 2014
Number weeks from April to September for every year - I want to number weeks from April to September for every year, such that week 1 starts 1st of April and ends the following Saturday and week 2 starts first Sunday of April and ends the following Saturday and so on.... till the end of September. How do I do that using TSQL. Thanks in […]
SQL Server 2012 - T-SQL
slow query performance - Hi All, I have a SELECT query which is taking more 8 mins. Can you please help me in making the query run faster (if possible) . There is no blocking . Seeing PAGEIOLATCH_SH waittype for most time. The table is a clustered index table. There is no non-clustered idx on mule_batch_id column. Query: use […]
SQL Server 2019 - Administration
\'REMOTE ACCESS\' setting flipped back to 0 overnight ?? - Any reason why our SQL Server 2016 Standard edition instance would have flipped the 'REMOTE ACCESS' setting back off? Here's what happened: - I ran the following code AS IS on both SQL Servers: sp_configure 'show advanced options', 1; GO RECONFIGURE; GO EXEC sp_configure 'remote access'; -- Display current setting GO --EXEC SP_CONFIGURE 'remote access', […]
SQL Server 2019 - Development
SSIS 2019 - Conditional Expression for the value of a variable- fails evaluation - Hi All, Ran into an error trying to evaluate the following expression for a variable value: @[User::varBadRows] > 0 ? (DT_STR, 50, 1252) ("There are " + (DT_STR, 3, 1252) @[User::varBadRows] + " rows with a non-matching SPID value.") : NULL(DT_STR, 50, 1252) I'm using Visual Studio 2019 Pro and my target environment is SQL […]
The backup set holds a backup of a database other than the existing 'MyDB' - I'm trying to restore a database from our production server to my local machine using the following script but still get the error, 'The backup set holds a backup of a database other than the existing 'MyDB' database. USE [master] RESTORE DATABASE [MyDB] FROM DISK = 'C:\MyDB.bak' WITH REPLACE, MOVE 'MyDB' TO 'C:\MyDB.mdf', MOVE 'MyDB_log.ldf' […]
Find row closest to date - Just having trouble getting this to work as I hoped. Trying to extract entire row from one table with a date closest and before another date in the 1st table.  Sample table and 1st try below. Any help is appreciated Trying to get: 1,    2020-08-05,  2020-08-03,   25 2,    2020-08-04,  2020-08-03,   34 3,   2020-07-28,  […]
SQL Select with condition - Hi, In my sql table,  there is a column which have string of text : Column 2ABF   CD06-000000001234506-0000000001156 306-000000000345206-0000000000356 I would like if the 1st character is 2 then  out put as ID               Code           Num1          Num2          Num3       Num4 2ABF        CD              123.45         11.56 if the 1st character is 3 then ID               Code           Num1          Num2          Num3       Num4 […]
Integration Services
SSIS package with Multiple Streams - I have a package with has multiple streams and calls the same SP. Why do streams are used in SSIS, like to multitask with the same SP? I do have a performance issue with this package. Will reducing the streams help? ( like less SP calls)  
 

 

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

 

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