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

Daily Coping Tip

Sign up for a new course, activity, or online community

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.

Do What Hurts

This editorial was originally published on October 22, 2019. It is being republished as Steve is on holiday.

A long time ago I heard a manager at a company say that if something is hard, we ought to practice it more and find ways to make it easy. Barring that, we ought to at least be comfortable with the task. I'm not sure if this manager made this up or read it somewhere, but it's the same thought expressed by Martin Fowler in this post: "if it hurts, do it more often."

I'm not sure that's the advice I want to use with everything. When my shins hurt from running, or my shoulder aches after hitting a number of volleyballs, often I want to take a break. At the same time, I know that stopping isn't always the productive thing. I can slow down and build up some strength and things will get better. My long running streak started with slow jogs for short distances, slowly building up the strength in my muscles and joints. Regularly hitting volleyballs and slowly increasing the number I hit allows me to get more done without hurting myself.

At the same time, putting a hand on a hot stove doesn't get better, no matter how slowly I increase the heat over time. There are some things that aren't worth doing more often to get better, but building software is one where we can get better. Our practice does improve skill, quality, and ability if you practice well. We can decompose our problems easily, we can work in steps, and we can (relatively) easily alter our course of work if we need to do so. In fact, quite a few of the software methodologies adopted in the last 20 years are designed to improve the entire process be ensuring we adapt our work to the customer with regular pauses to evaluate our progress.

When the pain of delays (procrastination) grows, we should find ways to reduce the hassles. Often the pain comes from difficulties, and when that is the case, we might do what Martin Fowler suggests: do it more frequently.

It works well for databases, as he points out in his post, though I'd caution the data professionals to consider the details in his post. Decompose the problems and make the changes across multiple steps, not all at once. When you do that, make sure you plan for pauses in the various stages, not just stringing together multiple scripts into one transaction. That will help you evolve the database along with the application while ensuring your customers can continue working as you make changes.

Steve Jones - SSC Editor

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

 
 Featured Contents

Block user objects from being created in a master database

Steve Rezhener from SQLServerCentral

Introduction The Master database. Just in case that you are not familiar with this database, the Master database is used in SQL Server to store all the system information, instance-level settings, logon information, database file locations, etc. SQL Server can't run without access to a fully functional master database. It's highly recommended not to use […]

Storage 101: Monitoring storage metrics

Additional Articles from SimpleTalk

Well tuned storage is essential for SQL Server performance. In this article, Robert Sheldon explains the metrics that are important to watch.

From the SQL Server Central Blogs - SQL Homework – November 2020 – Help!

Kenneth.Fisher from SQLStudies

If you ask any senior IT person What is the most important tool you have? there is a decent chance that ... Continue reading

From the SQL Server Central Blogs - Migrating SSIS to Azure – an Overview

Koen Verbeeck from Koen Verbeeck

For quite some time now, there’s been the possibility to lift-and-shift your on-premises SSIS project to Azure Data Factory. There, they run in an Integration Runtime, a cluster of...

 

 Question of the Day

Today's question (by Junior Galvão - MVP):

 

Self-numbered primary key creation

I have a database, called Stock, and I have the need to create a new table, called Orders, according to the code below:
-- Accessing the Stock Database --
Use Stocks
Go
-- Creating the Orders Table --
Create Table Orders
  (ID Int IDENTITY(1,1) Not Null Primary Key,
   CustomerID Int Not Null,
   SalesPersonID Varchar(30) Not Null,
   Quantity smallint Not Null,
   NumericValue numeric(18, 2) Not Null,
   Today Date Not Null)
Go
Right after creating the table, you choose to use some recursive CTEs the amount of 100,000 rows of records in the Orders table:
;WITH E1(N)    AS (SELECT 1 FROM (VALUES (1),(1),(1),(1),(1),(1),(1),(1),(1),(1))E0(N)),
      E10(N)   AS (SELECT 1 FROM E1 a, E1 b, E1 c, E1 d, E1 e, E1 f, E1 g, E1 h, E1 i, E1 j),
      TallY(N) AS (SELECT TOP(@RowCount) ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM E10)
INSERT INTO dbo.Orders (CustomerID, SalesPersonID, Quantity, NumericValue, Today)
 SELECT  CustomerID     = @RowCount+1-t.N
        ,SalesPersonID  = SUBSTRING(ca.Texto,ABS(CHECKSUM(NEWID())%126)+1,2)
                        + SUBSTRING(ca.Texto,ABS(CHECKSUM(NEWID())%124)+1,4)
                        + SUBSTRING(ca.Texto,ABS(CHECKSUM(NEWID())%124)+1,4)
        ,Quantity       = ABS(CHECKSUM(NEWID())%1000)
        ,NumericValue   = RAND(CHECKSUM(NEWID()))*100+5
        ,Today          = DATEADD(dd,ABS(CHECKSUM(NEWID())%1000),GETDATE())
   FROM TallY t
  CROSS APPLY (SELECT '0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzŽŸ¡ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝàáâãäåæçèéêëìíîïðñòóôõöùúûüýÿ')ca(Texto)
SELECT ID, CustomerID, SalesPersonID, Quantity, NumericValue, Today
FROM Orders
Go
Knowing that from the moment we create a new table containing a primary key, Microsoft SQL Server adds a Statistic, a feature that aims to help us get the dataset through the Select command faster. What will happen to the Histogram, its column structure that indicates how often data will be created?  

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)

Storing the Timezone

What datatype(s) are used to store a date and time with the time zone information?

Answer: datetimeoffset

Explanation: Only datetimeoffset stores time zone information. Ref: Datetimeoffset - https://docs.microsoft.com/en-us/sql/t-sql/data-types/datetimeoffset-transact-sql?view=sql-server-ver15

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
Could database with compat level 100 support columnstore index? - Hi everyone. I asked this question previously on other forum, but didn't get satisfied answer. I hope I could find the answer here. So, I have an instance which runs on SQL Server 2017 Developer Edition instance. I restored database ContosoRetailDW which had compatibility level 100. After restore operation, I run the following query: CREATE […]
Changing datatype in a column - Do I have to rebuild the Clustered columnstore index when we modify datatype in a column?   Thanks!
High buffer size for a table could mean either it has incorrect indexes or ? - or simply that the table is USED A LOT, right? -- Breaks down buffers used by current database by object (table, index) in the buffer cache (Query 51) SELECT OBJECT_NAME(p.[object_id]) AS [ObjectName], p.index_id, COUNT(*)/128 AS [Buffer size(MB)], COUNT(*) AS [BufferCount], p.data_compression_desc AS [CompressionType] FROM sys.allocation_units AS a WITH (NOLOCK) INNER JOIN sys.dm_os_buffer_descriptors AS b WITH […]
SQL Server 2016 - Administration
Page Verify = Checksum - Hi I'm belated changing the page verification option for a database from NONE to CHECKSUM.  I'm aware this only affects future writes to the database, and existing pages won't have that checksum calculated until they are updated or the relevant tables or indexes are rebuilt. My question is: would an ALTER INDEX ... REORGANIZE also […]
Audit connection which are connecting to a server using AG listener. - I am in a middle of removing a server which is part of AG and someone has asked me to see if there are users, connecting to that specific server using a listener name so I used a DMV to capture all that information. The script is below SELECT es.login_name ,es.program_name ,login_time ,ec.client_net_address ,ec.client_tcp_port ,agl.dns_name […]
Development - SQL Server 2014
How would I get the last record of a self-referential table? - This summer I authored a report that referenced nine tables in a query. This is against an older database. This is for a pharmacy application that someone back when wrote originally in a Microsoft Access application. Along the way somebody upgraded the database from the original .MDB to a SQL 2012 database, where it currently […]
SQL 2012 - General
Errors enabling and disabling Change Data Capture for 1 table - Hello, when we try to enable CDC on a table that is dropped and recreated each night, we get the below  error: Msg 22926, Level 16, State 1, Procedure sp_cdc_verify_capture_instance, Line 36 [Batch Start Line 0]Could not create a capture instance because the capture instance name 'dbo_appt_slots' already exists in the current database. Specify an […]
SQL Server 2012 - T-SQL
Performance Issue - I have a SQL server on a HyperV cloud.  The server harddrive is stored on the SAN.  I have separate LUNS (drive letters) to the mdf, ldf and tempdb files. When I run "select * from product" on my local copy, it takes 2 seconds.  When I run the same query on the sql server […]
SQL Server 2019 - Administration
Key locks on ghosted records - We're curious about locks that might revolve around ghost records that have been deleted.  Does anyone have an explanation for this scenario? Given the following table: CREATE TABLE [dbo].[TEST_TABLE]( [column_A] [nvarchar](30) NOT NULL, [column_B] [tinyint] NOT NULL, [column_C] [bigint] NOT NULL, [column_D] [int] NOT NULL, CONSTRAINT [i01TESTTABLEKEY] PRIMARY KEY CLUSTERED ( [column_A] ASC, [column_B] ASC, […]
SQL Server 2019 - Development
SQL Full text query too slow - I have some Full Text Catalogs and since some time ago, the query time really slow down, and the only solution I found until now is to rebuild the catalogs, sometimes more than once a day with command: ALTER FULLTEXT CATALOG TABLE1 REBUILD Why is necessary to rebuild the catalogs? There are other solutions for […]
SSRS 2012
Formatting parameter pane - I have over 30 parameters in my report. Is there a way to force the parameters into a particular format rather than having them line up in two columns when the report is run?
Powershell
Scanning to find sql instances/servers - We use MAPS tool to scan through our domain and then list out our sql servers/instances. How can this be achieved using powershell ? Thanks
SSDT
CDC Source tool in SSIS - varchar data mapping issue - I'm trying to introduce myself to the change data capture items in the SSIS Toolbox and have hit a problem with the CDC Source tool. I've been using this tutorial as a guide: https://www.mssqltips.com/sqlservertip/5815/sql-server-integration-services-ssis-cdc-tasks-for-incremental-data-loading/ So I have a source table with varchar data types in SQL Server, but in the CDC Source Advanced Editor it […]
SSIS performance issue: Data load from sqlserver2016 (EC2) - Mysql8.0 (RDS) - Hi, I am trying to Full Load  from Table on sqlserver(2016) to a table on Aurora My Sql database (RDS).The table has 1M records and taking 3 hrs to load it when I run it as a job on server. I am using ODBC 32 bit driver  and ADO.net Provider on the ETL side. The […]
Integration Services
Find MAX value from multiple datetime columns - This may have an easy resolution but I'm having difficulty finding it.  I'm creating a package that needs to take records that are new or updated since the last time the job run.  I have 2 DateTime columns Insert_date and Last_Updated.  I need records for newly inserted records and modified/last_updated records.  How do I accomplish […]
 

 

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

 

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