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

Daily Coping Tip

Leave positive messages for yourself to see regularly

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.

To Inifinity and Beyond With 1=1

There is one thing that Aaron Bertrand won't get mad at me for doing and that's creating an infinite loop with a WHILE (1=1) pattern. He wrote about this recently in a tip, noting that it's easy to create an infinite loop with code like this, something that never ends well.

I have written infinite loops in the past. A long, long time ago Radio Shack would put out TRS-80s on display, and a few of us would type a quick BASIC program to perform some math work on the screen over and over with an infinite loop. It often crashed at some point with an overflow, but for awhile it would look neat on the screen. Less neat to the salespeople who weren't always sure how to stop it and demonstrate something else without resetting the machine.

I've also created infinite loops by accident at various jobs. Those experiences have left me a little concerned about any loop that doesn't have a defined time to end. I usually use a technique similar to Aaron, with a call that might repeat the entire process if more data needs to be updated when my current loop ends.

There are plenty of people who spotted the error in the code and think they wouldn't create that problem in their looping code. However, I think few of us work alone on code for an employer, across time. Often someone else comes in to refactor or "improve" our code. The next person that adjusts this loop might join back to the main table and not realize they are creating an infinite loop. You'd hope they'd test this and find the problem, but I continue to see lots of "little fixes" deployed without being tested.

This is one reason I want a DevOps style process for database code, complete with automated testing. If you write a piece of code, you are responsible for including a test in the pull request so that the CI system can verify your code passes the test. This isn't a perfect system and it might not prevent all bugs, but at least a test will exist and someone can then check both the code and test and perhaps use the issue as a teaching moment.

We try and avoid loops in SQL Server, but that isn't always possible. As with most techniques in programming, we should strive to learn the best ways to use them, know the weaknesses, and avoid building code that has major flaws now. Maybe we also ought to add that we should ensure our code doesn't lead less experienced developers in the future to make simple mistakes. I'd say the 1=1 looping code does this and should be avoided.

Steve Jones - SSC Editor

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

 
 Featured Contents

PostgreSQL Date And Time Part 2

Shivayan Mukherjee from SQLServerCentral

In the second part of this PostgreSQL date time series, we examine a number of commonly used functions for getting current dates and times and converting strings to dates and times.

Use SQLAlchemy ORMs to Access MongoDB Data in Python

JerodJ from SQLServerCentral

The wide ecosystem of Python modules enables you get to work fast and effectively integrate your systems. You can use the CData Python Connector for MongoDB and the SQLAlchemy toolkit to build MongoDB-connected Python applications and scripts.  This article details how to use SQLAlchemy to connect to MongoDB data to query, update, delete, and insert MongoDB data.  Connecting to MongoDB Data  Connecting to MongoDB data is similar to connecting to any other relational database. Create a […]

What's the real story behind the explosive growth of data?

Additional Articles from Redgate

IDC’s recent Global DataSphere Forecast, 2021-2025 predicts that global data creation and replication will experience a compound annual growth rate of 23% over the forecast period. But what’s causing the growth? Where will all of that extra data be stored? And how should we, as data professionals, prepare for it? Read this blog to explore these important questions.

Real-Time Streaming using Power BI Streaming Dataset

Additional Articles from MSSQLTips.com

In this tip we will look at using a Streaming Dataset in Power BI to visualize real time data using the streaming service Azure Stream Analytics job.

From the SQL Server Central Blogs - Persist Sample Percent in SQL Server IS Fixed!

jsterrett from John Sterrett

Hi Everyone, this is John Sterrett. I am a SQL Server Consultant in Austin, TX. Last year I blogged about a feature called Persist Sample Percent. It had a...

From the SQL Server Central Blogs - Database Sizes

Kenneth.Fisher from SQLStudies

Quick query today. I needed a list of database sizes so came up with this: Nothing exciting, but I figure ... Continue reading

 

 Question of the Day

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

 

Unloading an Extended Stored Procedure

Normally an extended stored procedure is not unloaded from memory until SQL Server is shutdown. How can I unload an XP without stopping SQL Server?

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)

STRING_SPLIT Separators

I have a SQL Server 2017 database. I want to use the STRING_SPLIT() function to separate some data. For the separator, what are my options?

Answer: A single character separator

Explanation: In SQL Server 2017, STRING_SPLIT() only allows a single character separator. Ref: STRING_SPLIT() - https://docs.microsoft.com/en-us/sql/t-sql/functions/string-split-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
SSRS 2017 How to check which SSL cert is bound - Hello experts, I need to update the SSL certificate on our SSRS 2017 instance. However, in the Report Services Configuration Manager it lists the 2 certs without any room to expand the name or check the properties. So happens both the old and new SSL cert that our systems team assigned start the same way, […]
SQL Server 2016 - Administration
SQL Agent job - Can I run extended event session against 1 SQL agent job? I have a job which runs at 7 every day, takes about 10, 12, 14 hours to run. It inserts 2.5 million records into a table thru a bat file. To me, it should run fast but I am just trying to educate myself […]
Rebuild index - I have a table which is partitioned (Total 10). The table is 1.6 TB in size. Rebuild index on that is quite challenging, especially we have some resource constraints. I am wondering if there is a way to rebuild index, just for 1 partition. Just trying to educate myself.
SQL 2012 - General
There is insufficient sys memory in resource pool 'internal' to run this query - Hi All, I have an issue with production server , from SQL error log I can see "There is insufficient system memory in resource pool 'internal' to run this query. when i check the memory usage for 1 month , it is like around 35% everyday and also min memory is 1 GB and max […]
SQL Server 2019 - Administration
Multiple instance on SQL server 2017 with VS 2019.... ERROR 26 on Visual Studio - I have a system with multiple clients and each one in different virtual machines, I have proposed the task of joining all the clients in the same virtual, of course taking into account that they are all in the same version of sql server. my first tests failed as i installed each of the instances […]
SQL Server 2019 - Development
Need some help with tsql code - I have 4 tables (DevDB, TestDB, StageDB, ProdDB). All those tables have 2 columns (DatabaseName, Environment). There are tons of DBs which exist on Prod but don't exist in lower environment. I need help with writing a query which pulls data so I can see that let's say 1 specific database exists in stage but […]
Capture login information - I want to Capture Login information in table or view. who connected to database and when they connected. looking for script
How to grant Exec ON multiple Stored Procedures - Hi, I have multiple Stored Procedures that are named like _Test_01, _Test_02 _Test_03 I would like to grant EXEC rights to multiple Stored Procedures at once. Something like: GRANT EXEC ON [dbo].[_Test*.*] TO [udr_db_FocusOneUserRole] How can I Grant these in one line?
XML data extract - Hi I've been tasked with extracting information for a report where the field type is XML. THe SQL table contains 2 fields Personcode and XMLBody THe XMLBody Field contains information like the below example; Extarct the data string located here.
Issue with the SUM function - Hello friends, I have one question. It may be a little bit hard to explain but I will try my best. Let me know if my explanation is confusing. Right now I have a query that has a chain name and lots of repetitions of the same information. I am 99,9% sure that the reason […]
Formatting issue with percent - I have an issue that may be an easy fix for someone, but is not for me. I need to calculate Instock%. For this I need to take p.QTY (Forecast Demand) / s.OH (What is on hand) and get a percentage. For example p.QTY (Forecast) was 2 and Inventory On Hand is 100 now so […]
SQL StoredProcedure for data validation using REGEX in SSIS - hi, I have a requirement where we get data from Oracle source and destination is also Oracle db. Only validation is done in SSIS. So, i have to validate the data using regular expression  in SQL Storedprocedure (in ssis) and send bad data to a error log table with logging the record ( with table […]
Reporting Services
Hex-tile map (e.g. United States) in SSRS? - I've created them in Tableau and PowerBI but would like to do this in SSRS:
Powershell
SQL Server connection using Get-StoredCredential - Hi, I am currently able to log in using a trusted connection. I stored credentials for an SQL login in the Windows Credential Manager, but I'm not sure how I can use this for authenticating from a PowerShell script. Currently, I'm connecting: $con = New-Object System.Data.SqlClient.SqlConnection; $con.ConnectionString = "Data Source=my-apps-server;Initial Catalog=myDatabase;Integrated Security=true"; $con.Open(); # execute […]
Integration Services
Save Blob Storage Key in Package - Hi Guys, Is there a way to save the Blob Storage Key into a package/project so that it doesn't need to be modifed after deployment each time?   cheers Alex
 

 

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

 

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