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

Summer Break

This feels like a strange day in the summer, with a holiday yesterday (Fourth of July) and the weekend starting tonight. This is similar to the Friday after the US Thanksgiving holiday, which is usually a day when very little gets accomplished in most offices. I'll be a little more productive at home than I would be in an office, but I'll still have a bit of a holiday lull from yesterday and a weekend coming up. Actually, maybe I'll get plenty done since I'm sure my body is tired after working on driveway maintenance and (hopefully) rebuilding a trailer hub. (If you haven't guessed, I'm writing this before the break)

It's the start of the second half of the year and a time when many people take holidays. Schools are usually on break, so families often look to travel somewhere. Some of us might take a staycation, catching up on projects at home. I know I'll be doing that a bit this summer as a busy first half of the year has me way behind on a number of maintenance items and projects.

We all need a break, so this week I'm asking you what things you might do this summer with friends and family that provide a welcome distraction from work. I'm assuming you'll have some time off, even if it's just a weekend, so share a fun event or activity you're looking forward to enjoying.

With my kids getting older, we rarely get together. Even on some of the smaller holidays, my son won't come home from university. If we do get together, it's often just a meal, though we did have a fun afternoon of bocce after my daughter's graduation from high school. Maybe we'll get out this weekend and do that again.

My wife, kids, and I love music. Some of us play instruments, some of us sing, but we enjoy hearing music all the time. We also enjoy movies, and last year my family when to see Bohemian Rhapsody, which was amazing. The music is great and I recommend this entertaining and enjoyable film. We also saw Rocketman recently, a good, but sad film for me to watch. Perhaps we'll all go see Yesterday this weekend since we enjoy the music of The Beatles. We've been Marvel fans, so I'm sure Spider-Man is on our agenda. This particular reboot is my favorite so far, so that's a possibility as well. We might have a bit of a debate on which to go see or just go see both.

I've gotten away from most sporting events and live concerts at event centers due to the time commitments (and cost). These days my wife and I may go see a local musician or a comedy act, but more often than not a movie (at home or out) is a way we escape from some of the pressures of life.

Hopefully you have something you're looking forward to, so let us know today how you'll brighten up your summer months.

Steve Jones - SSC Editor

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

 
 Featured Contents

Some of my greatest mistakes

David.Poole from SQLServerCentral.com

You are never too experienced to make mistakes. An occasional dose of humble pie serves as a reminder to up our game.

How to read the SQL Server Database Transaction Log

Additional Articles from MSSQLTips.com

In this tip we will take a look at a SQL Server function that you can use to read the SQL Server transaction log to see what entries are made for database transactions.

10 steps you can take to be compliant worldwide – free whitepaper

Additional Articles from Redgate

Learn how data protection legislation is changing around the world and the 10 steps database teams can take to ensure compliance and defend against data breaches.

From the SQL Server Central Blogs - Comparing Execution Plans

SQLEspresso from SQLEspresso

When you run a query twice, and get dramatically different run times, your first step can be to try to identify the differences in execution plans. For many that...

From the SQL Server Central Blogs - Using the Announcement/News Part of SQLSaturday

Andy Warren from SQLAndy

One of the interesting but not often used features of the SQLSaturday tools is the announcement/news (in the admin tools, its Message Center | Announce News) to do mini-blog...

 

 Question of the Day

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

 

Cleaning Overhead

Why is it not recommended to run sp_clean_db_file_free_space() during normal production hours?

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

 

Redgate Database Devops
 

 

 Yesterday's Question of the Day (by Steve Jones - SSC Editor)

July 4 2019

It's Independence day in the US. Everywhere else, it's just a Thursday. Except for some newsletter subscribers in New Zealand. It might be Friday there.

If I want to get the beginning of July 4 in the US, which is midnight in the Eastern Time Zone, and I have the code below to give me the time in Christchurch, NZ. What is returned

DECLARE @t DATETIMEOFFSET = 'July 4, 2019 00:00:00 -4:0';

SELECT @t AT TIME ZONE 'New Zealand Standard Time'

?

DECLARE @t DATETIMEOFFSET = 'July 4, 2019 00:00:00 +5:0';

Answer: 2019-07-04 16:00:00.0000000 +12:00

Explanation: When Independence Day starts in the US, it will be 4:00 in the afternoon (16:00) in New Zealand. Ref: AT TIME ZONE - https://docs.microsoft.com/en-us/sql/t-sql/queries/at-time-zone-transact-sql?view=sql-server-2017 sys.time_zone_info - https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-time-zone-info-transact-sql?view=sql-server-2017 Happy 4th of July!

Discuss this question and answer on the forums

 

Featured Script

Generate views to correct the column collation on a target DB's tables automatically

GabyYYZ from SQLServerCentral

You find you are querying a vendor supported database where you're not allowed to make any collation changes, and which has a weird collation setup: default DB collation that matches your server and other databases all character related columns are explicitly a different collation that does not match your DB or server collation Rather than […]

/*
Create this proc in the DB you will be creating these views.

@targetDB: The DB your new views will be targetting
@collation: The target collation you want to change the columns to if they do not match
@prefix: Set to something like 'vw'
*/
CREATE OR ALTER proc [dbo].[usp_refreshViewsToDB]
@targetDB nvarchar(100), @collation nvarchar(100), @prefix nvarchar(10)
as
set nocount on
declare
@tablename nvarchar(512),
@viewname nvarchar(512),
@query nvarchar(max) = '',
@colID int,
@maxColID int,
@prefixfilter nvarchar(11)

set @prefixfilter = @prefix + '_%' -- Will append a _, so no need to declare it in @prefix

-- Part 1: Drop the existing views that start with the prefix you have in the argument.
-- Please note, if there are other views in this DB that start with the same prefix, they WILL be dropped
-- so make sure these special views are prefixed uniquely

select name [ViewName] into #viewsToDrop from sys.views where name like @prefixfilter

SELECT TOP 1 @viewname = viewname from #viewsToDrop
while (@@ROWCOUNT > 0)
begin
set @query = @query + 'DROP VIEW ' + @viewname + '; '
delete #viewsToDrop where ViewName = @viewname
SELECT TOP 1 @viewname = ViewName from #viewsToDrop
end
print (@query)
-- exec (@query) -- uncomment when you're ready to run for real

-- Part 2: Populate the table list
create table #RawData
(
TableName nvarchar(100),
ColumnName nvarchar(100),
Column_ID int,
DataType nvarchar(100),
Collation_Name nvarchar(100),
Create_Date datetime,
Type_Desc nvarchar(100)
)

set @query ='
;with COL as
(
select S.name + ''.'' + T.name [Tablename], C.name [ColumnName], C.column_id, ST.name [DataType],
case
when C.collation_name is null then NULL
else C.collation_name
end [collation_name], T.create_date, T.type_desc
from ' + quotename(@targetDB) + '.sys.columns as C
inner join ' + quotename(@targetDB) + '.sys.tables T on T.object_id = C.object_id
inner join ' + quotename(@targetDB) + '.sys.schemas S on S.schema_id = T.schema_id
inner join ' + quotename(@targetDB) + '.sys.types ST on ST.user_type_id = C.user_type_id
)
insert into #RawData SELECT * FROM COL'
exec(@query)

-- Part 3: Go through each table above and create a corresponding view to match it
-- Cannot be done as one big because each CREATE VIEW must be unique,
-- as GO cannot be put in an EXEC statement, so each table must be processed separately
select distinct TableName into #TableNames from #RawData
set @query = ''

SELECT TOP 1 @tablename = Tablename from #TableNames order by Tablename
while (@@rowcount > 0)
begin
set @query = 'CREATE VIEW ' + @prefix + '_' + replace(@tablename, '.', '_')
+ char(10) + 'AS' + CHAR(10) + 'SELECT ' + CHAR(10)
select @maxColID = max(column_id) from #RawData where Tablename = @tablename
set @colID = 1
while (@colID <= @maxColID) begin SELECT @query = @query + ' ' + quotename(columnName) + CASE -- this assumes IS NULL matches your desired @collation, -- and is not some third collation when collation_name IS NOT NULL THEN ' COLLATE ' + @collation + ' ' + quotename(columnName) ELSE '' end from #RawData where column_id = @colID and Tablename = @tablename if (@colID < @maxColID) set @query = @query + ',' + char(10) set @colID = @colID + 1 end set @query = @query + char(10) + 'FROM ' + @targetDB + '.' + @tablename + ' WITH (NOLOCK)' + char(10) print (@query) -- exec (@query) -- uncomment when you're ready to run for real delete #TableNames where Tablename = @tablename SELECT TOP 1 @tablename = Tablename from #TableNames order by Tablename end drop table #RawData drop table #TableNames GO

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
How do I GRANT permissions on these? - "Accidental" DBA here and we are trying to improve our security.  We have created a new user that has far more limited security for a particular purpose than the one previously used, but I need to GRANT the following to the new user: User needs to SELECT on sys.procedures and be able to execute OBJECT_DEFINITION() […]
DW - Data Extraction RI issue - We are taking approach for Extracting data from source to target but have your advice. Our approach is: 1) Drop the RI Constraints 2) Truncate the Tables 3) ReCreate the  RI Constraints 4) Extract data from source to target Now confusion is during this process before or during recreating RI constraints if we loose DB connection or […]
SQL Server 2016 - Administration
Key Lookups - I'm trying to come up with a script that will identify key lookups that have a certain percentage of the query cost. Like if the key lookup is 50% of the query cost then I want the result set.
SQL Server 2016 - Development and T-SQL
Procedure to find record in same table in multiple databases - I need to be able to return a recordset of server name and database name for all databases that have the 'humres' table which contains a record in the table with a column 'usr_id' with value of a passed in username param. i.e. create proc getDBs(username varchar(8)) AS ( ..... )
index usage help - Hi All, Will any index will be used if we use functions on a column referred in the where, what is the best way to re-write this condition? SELECT..... WHERE to_char(lastUpdatedDate,'YYYY-MM-DD')>=@dt Please suggest. Thanks, Sam
System.Net.WebException: 'The request failed with HTTP status 403: Forbidden.' - Post was not responded to here, so I moved it here:  https://www.sqlservercentral.com/forums/topic/system-net-webexception-the-request-failed-with-http-status-403-forbidden-2
Administration - SQL Server 2014
Question related to AG's - Hi All, We are using SQL Server 2014 Enterprise Edition. We have 2 node Availability groups for high Availability purpose. One node as primary and one for secondary. Now the plan is to have a DR setup which is a standalone sql instance which is remotely located. Can we setup log shipping between an AG […]
The MSSQL Standard edition, does it limit the number of Work Threads? - I have a server with 128 logical processors, 64 bits server, and with a Standard edition of SQL Server 2014, and my question is this: Considering that SQL Server connects an ERP with a high number of simultaneous connections (approximately 1,000), and the characteristic "Maximum calculation capacity" for each of the editions of SQL Server, […]
Development - SQL Server 2014
simple query question, using ROLLUP instead of COMPUTE - A database was upgraded from 2008 to 2014 sqlserver, a report that was running using  COMPUTE to summarize totals quit working, as this function was deprecated with SS 2012. I wrote this query some years ago, adapted from an Oracle database I was pulling similar information from. The original query gave nice totals by SystemUser, […]
SQL Server 2012 - T-SQL
Indexing question - Hi All, What is the main difference between normal index rebuild and online index rebuilds? is there any performance benefits ? does it avoid blocking on large tables ? What actually happens behind in offline index rebuild and online index rebuild. Trying to see if anyone can explain in layman terms. Its quite overwhelming if […]
SQL Azure - Development
Azure Data Migration - Hi New to Azure and looking for the best options/approach to transfer on premise data to Azure BLOB (initial load about 1 - 5 TB) and also incremental changes thereafter.  Can you please provide the best options available?   Thanks  
SSRS 2016
System.Net.WebException: 'The request failed with HTTP status 403: Forbidden.' - When my application code goes to set the parameters for a reportviewer control for an SSRS report, I get the System.Net.WebException: 'The request failed with HTTP status 403: Forbidden.' error Not sure why.   I've set the credentials to the default network credentials, and I know have rights to see that report.   Wondering why I can't […]
Integration Services
Executing Flat file query - Hi , I have table/procedure/function script in flat file, i'm looking for solution to execute scripts (flat file) in SQL server db using SSIS. I have tried to use foreach loop - flat tile connection and execute SQL task - seems incorrect. Any help much appreciated, Thank you!
SSIS version - I recently opened a SSIS soltion that is developed by another developer. And I modified a package in it, then saved in subversion. But I open again, we cannot open the script component. And later we found out that in the source file of the ssis package, my version is different version than the other […]
SQLServerCentral.com Announcements
Status Update 2 Jul 2019 - Things have slowed down, so not a lot of progress to report, but a few new items logged, so worth tracking here again. Fixes Admin payment report time zones match browsers contribution center performance issue and wording changes Search is getting close to a beta launch, but still waiting on some Google crawls. They haven't […]
 

 

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

 

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