Delaying Code Execution with Waitfor–#SQLNewBlogger

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

One of the rarely used commands for me is the WAITFOR command. This is a command that intentionally introduces a delay in the execution of your code. I sometimes use this when I need to pause code for a brief time, but I never remember how this structure works.

Hopefully this quick post helps me remember this in the future.

WAITFOR

This command does what it says; it waits for something. You have two choices here in what to wait for: a period of time or a specific time. The structure of the command is:

waitfor <type> <time>

The type can be either of the keywords TIME or DELAY. I often use DELAY, which is a period of time to wait for. When you use TIME, the execution stops until that specific time of day.

As an example, if I want to pause code for 5 seconds, I use this:

WAITFOR DELAY ‘00:00:05’

If I run this in SSMS or ADS, the query time for this will be 5 seconds. The default is ‘hh:mm’, so remember that if you want seconds, you need to include the hours and minutes.

For time, the parameter is a datetime format, so enter this as the time you would want to start code execution again.

Practical Usage

The main place I used this recently was in this code:

EXEC msdb.dbo.sp_start_job @job_name = ‘Second Job with Two Errors’, @step_name=’Fourth Step’
WAITFOR DELAY ’00:00:02′

I was testing some job tracking, and needed a job that failed. It usually runs in less than a second, but without the delay, sometimes the failure isn’t picked up from the job history table.

This is the type of place, often in testing or in some dependent process, where I want a delay.

 

SQLNewBlogger

This post too my about 10 minutes to write. I couldn’t remember how WAITFOR works, but SQL Prompt helped. As I worked through my testing, I stopped and took 10 minutes to write this up.

You can do the same thing. Show your example, and how you use it. Be creative and impress someone who might read your blog before they interview you.

Posted in Blog | Tagged , , | Comments Off on Delaying Code Execution with Waitfor–#SQLNewBlogger

Eyes Wide Open

Not many of us work in startup environments, but many of us do work with new databases that are created for new applications. These might be carefully designed, thrown together, or your database might be constructed by an ORM. In any case, I find many people make decisions and write database code for today, solving the problems that they see in front of them. they often do this with little data and a single system. They might have their eyes on using some new technology, and they decide on a data strategy without really considering what they will need later.

That seems to be what happened with Expensify, which started in the financial industry. Their system had requirements for low response times, multiple locations, and detailed logging. This required a robust database architecture, which turned out to be helpful when the company pivoted to a new business model. Their CTO talks about some of the problems he sees with startups making database decisions. I think many of these lessons are helpful for all organizations that are trying to ensure their database can grow and meet their needs.

I think one of the most common problems I see is that developers and leaders get enamored with new technology. There is a lot of promise in some of the platforms and designs that are being put forth. Some are even proving themselves in high-profile situations, but not all. For most of us, however, we aren’t going to be solving the same problems in the same way. As the article notes, we’re not Google, but we’re also no Uber, Facebook, or Spotify. Choosing to mimic their choices because of their success doesn’t necessarily map to our business model. I find no shortage of companies that struggle to adopt some new platform because they built a proof-of-concept and assumed the way the system works with small amounts of data. This becomes an issue later with the moderate or large amounts that they have over time.

I also see companies creating complexity, with the chance that they will need to deal with many petabytes or exabytes of data at some point. Face it, most of us will barely deal with terabytes of data in any particular system. We ought to plan for a high-performing system at that scale, not worry about a future that will not likely come. At the same time, we aren’t going to be dealing with megabytes of data, so if your developers only test on MBs, they are going to miss problems.

I like the advice to go into your decisions with your eyes wide open. Don’t copy others, and realistically think about what you will need. I believe that engaging a data professional early is helpful. Developers do some amazing things when they build software, but so often the majority of them don’t really think about the challenges of a database system. They don’t consider low response times or ensuring there are HA and DR (two separate things) strategies. They also forget about the challenges of aggregation and reporting lots of data. Most humans work with a few rows of data at a time, which is what developers do on their systems. When you need to aggregate things, or all your customers are generating a workload, that’s when a data professional can help ensure you’ve properly indexed entities and planned for a demanding workload.

I do like the common sense advice that most startups won’t outgrow a relatively modest single database server. Many applications might not as well, but that doesn’t mean you can put all your eggs in that one server basket. Make sure if it dies that you have multiple people that can recover it and ensure your system is quickly running in another place. There are different ways to handle this, but engage someone that knows your platform and have them ensure you have some staff, operations or developers, that understand how HA and DR work in your environment.

Lastly, be secure. I really like the idea of always using stored procedures. I know this becomes a pain for developers, who now write code in two places, but this really helps you ensure better security, and maybe more importantly, ensures you can tune one part of your code regularly, the database side, without impacting the other side.

Steve Jones

Listen to the podcast at Libsyn, Stitcher, Spotify, or iTunes.

Posted in Editorial | Tagged , | Comments Off on Eyes Wide Open

Daily Coping 30 Aug 2021

I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag. 

Today’s tip is to donate some items to a charity.

I know this happened a lot last year. The local Goodwill stopped taking some things because so many people have up some of their possessions.

I’ve had a few things ready, so I’m giving away some bikes that still work, but the kids don’t ride anymore. I’m also giving away a few more dress clothes. I haven’t worn in years, they’re in good shape, and they don’t fit me. I rent suits now.

Posted in Blog | Tagged , , | Comments Off on Daily Coping 30 Aug 2021

Date Slippage in the Tesla Model Y Order Process

This is part of a series that covers my experience with a Tesla Model Y. If you are thinking of ordering one, I’ve got a referral code. You get 1,000 free Supercharger miles and so do I. Use: http://ts.la/john92950

I ordered a Tesla Model Y in May 2021. I wrote about the decision a bit, and as of this date, I haven’t gotten the car yet. When I took the test drive, the salesman noted that cars would likely be delivered in August then. Maybe July, but likely August to September. I ordered that night, May 21.

I didn’t track this explicitly, but the first time I checked on Jun 1, I had a month range. Here is the summary of what I’d seen as the possible delivery dates. The first date is the day I checked.

  • May 22 – July-Sept
  • Jun 1 – Aug-Sept
  • Jul 6 – Aug 14-Sep 3
  • Jul 18 – Aug 15 – Sep 4
  • Jul 23 – Aug 18 – Sep 10
  • Jul 30- Aug 21 – Sep 10
  • Aug 4 – Aug 26 – Sep 15
  • Aug 10 – Aug 27 – Sep 16
  • Aug 16 – Aug 26 – Sep 15
  • Aug 18 – Aug 27- Sep 15
  • Aug 19 – Aug 28 – Sep 16

Mostly things have slipped, but last week things improved by a day. I can’t imagine how hard it is to predict these days, given a large manufacturing environment. I do like seeing the updates, and I don’t think they need to keep emailing me. It’s a few minutes to check if I want to know.

As I get closer, I keep checking daily. I’m out of town this week, so having it slip to Aug 30 at the earliest is fine.

When I checked on Jun 1, this was when I saw a story that the third quarter was sold out. When I looked at the ordering process, the estimate in the tool was October, so I was glad we’d ordered that day. Not to mention May 22 had a $500 price increase, and a few more since.

When I started this process, delivery was November, and when I checked the date for my last post, things were delivering in December. This week I saw a note that you can’t get a Model Y in the US before 2022 right now, in mid August.

Priorities and Changes

One thing I’ve seen a few people note is that the higher priced models, the performance ones, sometimes will jump in line ahead of the cheaper ones. I have the lower Model Y version, the longer range one. There is no standard range one right now.

I understand Tesla might want to get those cars out quicker, as they add more to the bottom line, but I don’t know how many they’d have to prioritize to make a material difference. I certainly do think that the Plaid Model S and Model X might get re-prioritized slightly by cost rather than order date, but I don’t really know.

Just as likely, in my mind, is a glitch in their process and their picking the dates they send to customers.

I don’t feel too upset that a couple week slippage has appeared from the first date. It gives me a little more time to get prepared and get money ready, as quite a bit is due at delivery. Plus I am doing some work getting my old car ready to sell.

Other Possibilities

I saw a Ford Mach-E recently at the gym. At first I thought it was a Model Y with a Mustang badge on the front. I walked around, and realized it was a Ford. It’s nice looking.

20210807_090925

If you order this, with the standard range version (230mi range), it’s 16+ weeks on the Ford site. If you want extended range, 302 miles, it’s 24+ weeks. That’s longer than Tesla.

I got a mailer about the BMW Electric cars, and that caught my eye. They don’t deliver until next summer.

I considered a Polestar 2, but I was a bit concerned that it’s another 1.0 car, and not a lot of charging infrastructure, plus lower range. Those say delivery in September, which is good.

Ultimately, no one has a track record here, and as I’ve watched the Bolt, the Leaf, Tesla, and other cars, it takes time to work out bugs. I think especially with the software, which is what I’m most concerned about.

Summary

I’m camping this week, so even if the car were available Aug 26, I couldn’t get it until next week. I’m hoping I get an update sometime while I’m in South Dakota that gives me a specific date when I can go pick it up. Hopefully this is the week of Aug 30 or Sep 6.

I’m certainly excited and ready.

Video versions of these posts on My Colorado Tesla Experience Channel. You can see all of these posts by following the Tesla tag.

Posted in Blog | Tagged , | 3 Comments