They.

They are destroying democracy.
They are destroying the middle class in this country.
They are racists.
They are the ones who separated immigrant families and kept children in cages.
They are the reason why we have Trump as President.
They are the reason why we have a septuagenarian as the President, again.
They don’t believe in social programs such as free healthcare and education.
They don’t believe in science.
They don’t believe in facts.
They are liars and unethical.
They are selfish and value individualism more than the community.
They are less educated and less curious.
They are consumers and not creators.
They don’t have fiscal responsibility.
They are hysterical and cynical.
They are materialists.
They are nationalists.
They believe in closed borders.
They appreciate capitalism and condemn socialism.
They do what they can to avoid paying taxes but are against universal income.
They want to cancel, ban, or deplatform those with who they disagree.
They blame others for culture appropriation… of a culture that isn’t theirs.
They are vicariously offended.
They are classists.
They discriminate against people who look or talk differently than them.
They agree with science, but only when it is convenient.

They. Are. Us. All of us.

We can change!

Thankful

I am thankful. But there is something special about this time of the year, the warm colors, the reds, oranges, and yellows of the leaves, the colder temperatures, it’s all perfect to feel the beauty and experience of nature but also our vulnerability to it. I am thankful I can experience this.

This year has brought us many discomforts and pain due to the pandemic and the many social issues that we are experiencing, but even with all of that, there are many things that we can all be thankful for.

I am thankful for the gifts around me, not the physical gifts, but the amazing gifts that life has given me, such as my wife, my kids, my family in general, our health, and many more things that bring lasting joy to life.

This year brought me a health scare after my Garmin watch alerted me of an irregular heartbeat, twice. I then got an irregular EKG at the hospital, but later, a more in-depth test, a cardiac stress test, showed normal results. I am very thankful for that.

It’s hard to see the light and feel thankful when the abundance of negativity and bad news is placed in front of us daily. This is not healthy; watching the news and negative social media will more likely result in more struggle and pain.

Doomscrolling is real, and it’s not easy to get out of this bad habit. I am thankful that I don’t have that bad habit anymore, my life feels lighter, and I don’t feel the anxiety created by following toxic social media topics and people.

I am thankful because I am aware that we all have the capacity to improve our lives, that we can do better, and that better times are always ahead. I feel positive about that.

I hope you and your family are doing well, and Happy Thanksgiving, everyone!

Be Patient

Patience is something you cannot afford to ignore in your life. Patience needs to be present in your education, job, company, investments, and family.

Many of us confuse patience with complacency, and it’s not the same. You want to be patient while training yourself to do a better job, start and grow a company, save and invest, etc. but you cannot, and should not, be complacent. I myself, I’m learning to be more patient with my goals by being focused and changing my habits.

Set specific goals and get to them, one at a time. Be patient. Complete your goals, and then enjoy those achievements. Appreciating and learning to enjoy what we already have is key. Being patient does not mean you have to wait and live your life in the future. It just means that you have to be OK with waiting to see your hard work and investment results.

Having patience doesn’t mean to wait for retirement to do something you really like. Patience means to do what you really like and maybe wait to get a financial benefit from doing that.

Financial compensation is something we all look for, but it’s not the only benefit or joy in life. Learn to have enough to cover your bases like food and shelter, and leave some more to save and invest. You can enjoy time off, vacation, travel, and you can smile and be happy today. It’s possible if you change your priorities and expectations. Besides, we know what today looks like, we can do something about it today, but the future is often different from what we imagine today.

If you are looking for something greater or anything you cannot accomplish today, plan for it, set a date, and wait. Be patient. Be happy. Smile.

Focus and embrace new habits

About a while ago, I wrote a note about slowing down, taking the time to enjoy what we are doing, and focusing on one thing at a time.

I am running an experiment in my own life. I’m trying to slow down and focus intimately on the task at hand, which is not easy. Distractions are everywhere, and technologies such as our smartphones and social media make it nearly impossible to escape their digital crack. I want to allow myself to enjoy my surroundings and enjoy the present instead of focusing on just what’s ahead, or worst, what’s in the past.

In the book The Power of Habit, Charles Duhigg writes about ways of creating new habits. He describes the habit loop as a practical way to create long-lasting habits. The habit loop consists of a cue or trigger, a routine, and finally, a reward.

The habit loop is a widely used method by many industries, including the game and social media organizations, to get us addicted to their products. A good example of this is your smartphone notifications; that’s what triggers your craving brain, it makes you look at you social media app or email without thinking about it, and finally, it gives you a reward in the form of a new reply, a new like, or a new follower.

This habit loop is something we can use to our benefit, we can replace or use an existing trigger and follow a new routine and a new reward to accomplish something we want, instead of something someone else wants us to do or see.

So the habit I am trying to replace is the habit of reaching out to my phone or computer as often as I do today. And to do this, I am experimenting with using existing cues that make me look at my social media, email, etc., and instead use those same cues and triggers to do something else. I really want to do something that will keep me focused on my goals and the tasks I assign to myself.

For example, every morning, when I wake up, I see my phone, which immediately triggers my brain into picking it up and going through emails, scrolling through my social media apps, etc. Lately, I have been placing my kindle or a book in place of my phone, and every morning when I wake up, I don’t even think about it; I pick up the kindle or book and read for at least 20-30 minutes. Reading a book is more beneficial and relaxing than wasting my morning time with the digital crack, making me feel anxious and stressed.

If you see, the cue is the same, the routine is the same as I’m still picking an object and looking at it, but the reward is even greater now; at least for me, it is. I replaced a bad habit with one that fulfills my goal of reading more books, and at the same time, I feel focused and accomplished doing this.

Changing habits is what I am focused on right now; in the past, I focused on creating new habits without replacing bad ones, and that was a mistake. The best way to focus, to slow down, and to be more present is to change your habits, but doing it without adding complexity or having to remember to do new things. Make it as simple as possible, use the same triggers that make you waste time looking down at your phone, and pick better routines.

You owe it to yourself and to the people around you.

How to (efficiently) update millions of records in a SQL table

You need to update one or more columns in a table with millions of records with data from another table, what’s a good way of going this with low risk and in an optimized way? One of my favorite ways of dealing with millions of records in a table is processing inserts, deletes, or updates in batches.

Updating data in batches of 10,000 records at a time and using a transaction is a simple and efficient way of performing updates on millions of records. The key is to batch out your data to allow you to process a smaller number of records at a time.

Example:

use DatabaseName
go

DECLARE @batchId INT
DECLARE @batchSize INT
DECLARE @results INT

SET @results = 1
SET @batchSize = 10000
SET @batchId = 0

-- when 0 rows returned, exit the loop
WHILE (@results > 0)
	BEGIN
		BEGIN TRAN;

		UPDATE Table1 SET columnA = Table2.columnA
		FROM Table2
		INNER JOIN Table1 ON Table2.Id = Table1.Id
		WHERE Table1.columnA is null
		AND (Table2.Id > @batchId
		AND Table2.Id <= @batchId + @batchSize)

		SET @results = @@ROWCOUNT
	
		-- next batch
		SET @batchId = @batchId + @batchSize

		COMMIT TRAN;
	END

-- the sql below is just to measure the performance of this update, it is not needed to update your data.

DECLARE @startTime DATETIME

SELECT  @startTime = GETDATE()
SET STATISTICS PROFILE ON
SELECT  COUNT(*)
FROM Table1 first OPTION (RECOMPILE)
SET STATISTICS PROFILE OFF
SELECT  'It took ' + CONVERT(VARCHAR(8), DATEDIFF(ms, @startTime, GETDATE())) + ' ms'
GO

In the query above we declare the following variables to do the batching:

  • @results – this variable will hold the number of records updated; when zero, the query will stop. This is to avoid an infinite loop.
  • @batchId – this is set to zero initially, and it is used to compare the table id against it, and after each update, it is set to the id plus the batch size. This allows splitting the millions of records into batches.
  • @batchSize – the number of records to update at a time.

It is important to know that the above algorithm will only work when your table’s primary keys are of type int. If your table’s primary keys are guids, the above will not work.

The section at the end of the query is only used to review the performance of your updates, it is not necessary to update the data and it is a nice way to see how the query performs overall.

I hope the information in this post is helpful, and it helps you learn a simple way to update millions of records in batches, making it easier and lower risk than attempting to do it all at once.