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
 

Organized Learning

I really wish I'd do something like the DBA Training plan from Brent. Honestly, I don't have the time to do it the way he is, and certainly can't respond to any volume of emails, but I applaud the way he's doing this. Brent is sharing a lot of ideas and information on how to start getting a handle on your environment. As of this writing, there are 8 posts (part 8). I expect more in the future.

Becoming a DBA is often a random collection of experiences that almost everyone goes through in a different order. Maybe you started by having to recover a database with a restore. Maybe it was the need to install the server software and configure users. Maybe you find yourself more interested in writing database queries in T-SQL than methods in C#. However you learn, there are two things I know: your environment will drive your learning and there's always more to learn.

My start as a DBA came about when I needed to install a SQL Server instance to handle a new application. It was important that I understood the general admin duties to ensure backups and manage security. At first I didn't think much of the platform, but as I tried to troubleshoot performance issues, I started to learn about how connections are made, resources are used, and what bad T-SQL looks like. From there, I moved on to more development before coming back to the admin side later.

It would be great to have a class that teaches you to be a DBA, but really, the job has somewhat varied at each job I have had. There are some specific things that are important at every job, but the exception is often the rule as to how you ensure your environment works well. Once the system is in production, it becomes very hard to change anything, from security to code, without lots of testing and approvals. I find that often trying to work within constraints drives a lot of learning, though not often deep or varied enough to investigate all the options.

I don't know everything about SQL Server, but I have developed two very important skills in my career. I've learned how to learn, by reading, researching, and practicing new skills. I feel comfortable that I can come up to advanced beginner on a topic very quickly, usually competent enough to make something work. Second, I've learned how to ask for help. I'm lucky in that I have lots of friends I can call on for questions in specific areas. If you don't know someone that's an expert, I hope you know about #sqlhelp on Twitter and the forums at SQLServerCentral. These are great places to get help on whatever is troubling you about SQL Server.

Steve Jones - SSC Editor

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

Redgate SQL Source Control
 
 Featured Contents

Contribute to the SQLCop Project

Steve Jones - SSC Editor from SQLServerCentral

Learn how you can contribute a chance to the SQLCop project.

Redgate Takes over the SQLCop Project

Press Release from SQLServerCentral

I am happy to announce the Redgate Software and I are supporting and taking over stewardship of the SQL Cop project at this point. With permission from its founder, George Mastros, we will host the main repository for the project at https://www.github.com/red-gate/sqlcop. This should be considered the official repository for the code from this point […]

How to convince your boss you need SQL Server monitoring

Additional Articles from Redgate

You’ve read the State of SQL Server Monitoring Report and you’ve decided you need a SQL Server monitoring tool to cover your estate fully. Now you just need to convince your boss to get on board. Read our blog to find out how to do it.

Executing Dynamic SQL Using sp_executesql

Additional Articles from Database Journal

Learn how to create and execute dynamic SQL in your SQL Server projects!

From the SQL Server Central Blogs - Check Out the Updated Violin Plot Power BI Custom Visual

Meagan Longoria from Data Savvy

I wrote about the violin plot custom visual by Daniel Marsh-Patrick back in February. I thought it was a good visual then, but version 1.3 has recently been released...

From the SQL Server Central Blogs - Collecting Server Performance Metrics: PowerShell

Bradley Schacht from Bradley Schacht

In a recent post I wrote about collecting server performance metrics using Performance Monitor, a free utility built into Windows. With a little work up front, we are able...

 

 Question of the Day

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

 

Moving a Table

I have a developer that has built this table in his own schema on a SQL Server 2017 database:
CREATE TABLE SallyDev.CustomerLoad
(   LoadKey         INT
  , CustomerKey     INT
  , LoadTimestamp   DATETIME2
  , CustomerName    VARCHAR(200)
  , CustomerCompany VARCHAR(200)
  , Status          TINYINT);
They now want me to move this to the ETL schema for further testing with our application. What code will move this table?

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)

Tracking the Change

My SQL Server 2017 instance is acting strangely. I find that the cost threshold for parallelism has been reset back to 5 sometime in the last day. Where can I look to find out when this value was changed?

Answer: The SQL Server error log

Explanation: Changes made to the cost threshold for parallelism are written to the SQL Server error log. Ref: sp_configure - https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-configure-transact-sql?view=sql-server-2017

Discuss this question and answer on the forums

 

Featured Script

Create a Tally Function (fnTally)

Jeff Moden from SQLServerCentral

Many people have published high performance, read-less, Inline Table Valued functions that use Itzik Ben-Gan's wonderful "Virtual Numbers Table" to replace WHILE loops and other forms of RBAR. This one is Jeff Moden's version.

CREATE FUNCTION [dbo].[fnTally]
/**********************************************************************************************************************
Purpose:
Return a column of BIGINTs from @ZeroOrOne up to and including @MaxN with a max value of 10 Quadrillion.

Usage:
--===== Syntax example
SELECT t.N
FROM dbo.fnTally(@ZeroOrOne,@MaxN) t
;
@ZeroOrOne will internally conver to a 1 for any number other than 0 and a 0 for a 0.
@MaxN has an operational domain from 0 to 4,294,967,296. Silent truncation occurs for larger numbers.

Please see the following notes for other important information

Notes:
1. This code works for SQL Server 2008 and up.
2. Based on Itzik Ben-Gan's cascading CTE (cCTE) method for creating a "readless" Tally Table source of BIGINTs.
Refer to the following URL for how it works.
https://www.itprotoday.com/sql-server/virtual-auxiliary-table-numbers
3. To start a sequence at 0, @ZeroOrOne must be 0. Any other value that's convertable to the BIT data-type
will cause the sequence to start at 1.
4. If @ZeroOrOne = 1 and @MaxN = 0, no rows will be returned.
5. If @MaxN is negative or NULL, a "TOP" error will be returned.
6. @MaxN must be a positive number from >= the value of @ZeroOrOne up to and including 4,294,967,296. If a larger
number is used, the function will silently truncate after that max. If you actually need a sequence with that many
or more values, you should consider using a different tool. ;-)
7. There will be a substantial reduction in performance if "N" is sorted in descending order. If a descending sort is
required, use code similar to the following. Performance will decrease by about 27% but it's still very fast
especially compared with just doing a simple descending sort on "N", which is about 20 times slower.
If @ZeroOrOne is a 0, in this case, remove the "+1" from the code.

DECLARE @MaxN BIGINT;
SELECT @MaxN = 1000;
SELECT DescendingN = @MaxN-N+1
FROM dbo.fnTally(1,@MaxN);

8. There is no performance penalty for sorting "N" in ascending order because the output is implicity sorted by
ROW_NUMBER() OVER (ORDER BY (SELECT NULL))
9. This will return 1-10,000,000 to a bit-bucket variable in about 986ms.
This will return 0-10,000,000 to a bit-bucket variable in about 1091ms.
This will return 1-4,294,967,296 to a bit-bucket variable in about 9:12( mi:ss).

Revision History:
Rev 00 - Unknown - Jeff Moden
- Initial creation with error handling for @MaxN.
Rev 01 - 09 Feb 2013 - Jeff Moden
- Modified to start at 0 or 1.
Rev 02 - 16 May 2013 - Jeff Moden
- Removed error handling for @MaxN because of exceptional cases.
Rev 03 - 07 Sep 2013 - Jeff Moden
- Change the max for @MaxN from 10 Billion to 10 Quadrillion to support an experiment.
This will also make it much more difficult for someone to actually get silent truncation in the future.
Rev 04 - 04 Aug 2019 - Jeff Moden
- Enhance performance by making the first CTE provide 256 values instead of 10, which limits the number of
CrossJoins to just 2. Notice that this changes the maximum range of values to "just" 4,294,967,296, which
is the entire range for INT and just happens to be an even power of 256. Because of the use of the VALUES
clause, this code is "only" compatible with SQLServer 2008 and above.
- Update old link from "SQLMag" to "ITPro". Same famous original article, just a different link because they
changed the name of the company (twice, actually).
- Update the flower box notes with the other changes.
**********************************************************************************************************************/
(@ZeroOrOne BIT, @MaxN BIGINT)
RETURNS TABLE WITH SCHEMABINDING AS
RETURN WITH
H2(N) AS ( SELECT 1
FROM (VALUES
(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
,(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
)V(N)) --16^2 or 256 rows
, H4(N) AS (SELECT 1 FROM H2 a, H2 b) --16^4 or 65,536 rows
, H8(N) AS (SELECT 1 FROM H4 a, H4 b) --16^8 or 4,294,967,296 rows
SELECT N = 0 WHERE @ZeroOrOne = 0 UNION ALL
SELECT TOP(@MaxN)
N = ROW_NUMBER() OVER (ORDER BY N)
FROM H8
;
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
Can't add user to db_owner role - I have a simple SQL Server 2017 database in which I am unable to add one of the database users to the db_owner role.  I have confirmed the user is actually setup in the database.  When I try to add it to the db_owner role from my own machine, using SSMS or t-sql, I get […]
SQL Server 2017 - Development
In-Memory OLTP - N00b Question - I am new to the In-Memory OLTP world (yes, I am a little behind the times, mock me if you must :)) My question is the following: If I have a time tracking which is written most often but has occasional updates applied. Data is not deleted. Would these tables be good candidates for In-Memory […]
SQL Server 2016 - Administration
Getting counts before deleting data - Hi, I'm working on data archiving to Archive database from source database. I have to insert data from source database table to archive database and then delete from source. But I want to perform a check by getting no.of rows inserted  is equal to no.of rows that are selected to delete. Table1 is parent table […]
Access and rights - Vendor app is requesting for db_owner role to do some development, when I asked for the reason for db_owner then they requested the following access for development. Rights to execute following actions. Table creation, Stored procedure, trigger creation, Views creation and rights to drop, delete and truncate tables. Creating reference And may be some activities […]
How to identify if data is skewed in a table - Hi, I'm seeing key lookup which is taking 95% of time for a query. I have verified and made sure that there is no index fragmentation and stats are up to date. Still the query is taking almost 8 seconds to complete. I want to check if the tables are skewed with data ? How […]
Login error with AD authentication remotely with SSMS - Hello all, I am getting this error on one of our servers and only when logging in remotely with a Windows AD account . Local SQL auth works fine. All ports are open but something is blocking it somewhere on the server please see capture. "The target principal name is incorrect. Cannot generate SSPI." […]
misaligned log IOs - While restoring a log on a secondary replica to prepare a database for joining an availability group I suddenly received a flurry of 'There have been n misaligned log IOs which required falling back to synchronous IO' messages. In 20 years working with SQL Server this is a completely new message to me. A Google […]
Administration - SQL Server 2014
Migration Project - Hi This is the first time I've had to migrate a mission critical 30 vCPU SQL VM from 6 year old VMWare hosts ( Dell R920s I think ) to new Nutanix kit ( the Nutanix spec as yet unknown - but I will post back as I get it ). The SQL app is […]
SQL 2012 - General
Build Failed for SSIS Solution in VS2017 - We have our SSIS solution up and running in VS2012, and we want to migrate to VS2017. But when we open the solution and do a build on VS2017 (Version - 15.9.14), without changing the target server or any settings, the build failed with the below error message. Current version running and built successfully in […]
Performance Improvement Tips - Hi, When you are handed over an environment and have to do performance improvement. What would you do? I know you may be thinking first why do  you need or thinking about improvement. I mean if is just to check if we can make it little more faster. Couple of things I am doing CPU […]
SQL Server 2012 - T-SQL
Dual Duplicates redress. - I have created a stored procedure that pulls personal information from several tables. The output is formatted into XML. I need to manipulate two of the elements to be. I have written a sub-query to return the duplicates within two data fields.I read the base query into INSERT INTO #temp_dups SELECT [RowNumber], [Party], [EID], [BID], […]
Reporting Services
Help issue with iif and basic mathematical functions - Now this seems simple but its driving me up the wall for something that seems so simple. I am attempting to preform an mathematical action on using the value from a text box in a table within an iif statement, for example if the value in textbox1 is numeric then display the value of textbox1 […]
SSRS 2017 Fresh Install - First I know this is the wrong place but SSRS 2017 does not appear as yet, so........ Fresh install on SSRS, build 14.0.600.1274, all went well until trying to trying to connect and then get the error (from the logs\) "Could not find stored procedure 'GetAllFavoriteItems'" and beyond that stuck, any ideas?
Analysis Services
Model with unrelated tables - Today I came across a modeling that I did not understand. I opened a data warehouse project with the following tables: Dimensions: - Dim_Store - Dim_Date - Dim_Customer - Dim_Location Fact: - FactSales The fact  FactSales is relating to the above dimensions, so far ok. But when I open the project in SSAS there are four […]
Integration Services
VisualStudio/SSIS - Exporting from MySQL to MSSQL using ADO.Net connector -Fail - Hi, I'm in the process of creating a package that will export X data from a table in MySQL and import into an almost identical table in MSSQL. I have successfully configured the connection to MySQL using a '.Net providers\ MySQL Data Provider' and can connect to the DB fine. I have also successfully configured […]
 

 

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

 

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