#TSQL2sday #149: T-SQL Advice you’d give to your younger self

Hello! As I mentioned on my invitation post, this month I’m hosting the T-SQLTuesday and my theme was “T-SQL Advice you’d give to your younger self”. Here’s my contribution.

If I could go back in time, and maybe send myself an anonymous email (which would probably go to my spam box? hmmm), this is what I’d like to find:

  • It’s ok to use Google, like every day multiple times a day. Sometimes we face issues and we may tend to get super deep into it, but forget that we do not need to re-invent stuff. Others have likely been through what you are living and if they were great human beings they even talked about it on the internet. Isn’t that wild? We must learn to be humble. It’s OK to have your colleagues and managers see an open Google tab, as long as you are delivering the job you’ve been given, you’ll be just fine.
  • Comment your code! I’ll give you a week and you’ll forget what you were doing anyways so leave some useful comments. That will help you and others who will pick up on your work after you. I like to add the following to all my scripts: author, date, project name and a little description. Sometimes I even add the name of the person who requested the work, makes it easier to talk directly whit whom I need to.
  • Do you know those times when you find yourself repeating the same piece of code over and over? There are better ways to version your code, but as a starting point, you can create a folder on your documents and start adding sql files there that you can refer to later. Here’s what I have on my folder:
    • how to search for a column or table with a specific name;
    • how to use date functions with examples such as DATEADD, DATEDIFF;
    • how to check for temp tables column names;
    • how to format phones when they’re all messed up;
    • how to find databases, filenames and paths;
    • getting a path for sql server log error message;
    • check you database size;
    • how to check for used and used space on the database
    • and whatever else your heart desires! This is the type of work that I do and that later will save my time. I’ll probably make more posts to show my solutions to this handy scripts 🙂
  • Always ident your code and use Uppercase for all commands. You’ll notice that one day you won’t even trust people who don’t do that (oh, the drama).
  • If you have someone senior than you at work, ask them questions when you’re stuck, they probably will solve the problem faster, more elegantly and you’ll learn how to do it by watching them!
  • Make it a habit of NOT using “*” when you are doing a SELECT query. It’s ok to do it once so you can see the table, but then your real query should list the fields you want to see, by name. ✨ Marie Kondo your query and let go of what does not serve you anymore ✨
  • Don’t wait until you are an accidental DBA to learn the fundamentals. Even if you just want to be able to discuss problems with them.
  • Learn how to read the query execution plan. It will help with understanding bottlenecks and how to optimize your queries.
    • …also, when optimizing, don’t struggle about the milliseconds you might save. Nobody will notice. You want to focus on the changes that will give you the biggest differences on execution time. Think about how big the impact will be by projecting “if I don’t fix this will someone come to my table with a very angry face?”
  • Whenever you start writing an UPDATE or DELETE statement, immediately write FROM… WHERE… This will save you the headaches of forgetting to finish your command and updating or deleting everything at once.

That’s it for me. Hope this was helpful for some beginners out there. Now tell me…

What do you wish you knew earlier? 🙂

#TSQL2sday #149 Invitation: Blog about T-SQL Advice you’d give to your younger self

T-SQL Tuesday is a monthly blogothon where a host chooses one topic and bloggers around the world give their ideas about it. This month is my first time being the host and I’m so excited!

April’s theme: if you could give advice about T-SQL to your younger self, what would you say? I’m not defining any more specific sub-topics here, I’m opening the floor to hear ideas about your past experiences and what you wish you knew better back then.

Some rules:

  • You have to publish your post next Tuesday, on April 12th.
  • Include the T-SQL Tuesday logo, and if somebody clicks on the logo, it has to link back to this post.
  • Include a link to this blog post, or after you publish it, leave a comment here so I can track you down for the roundup blog post next week. If you want to share via Linkedin as well or other social media, please do and I’ll link you too.
  • Isn’t this idea awesome? Do you want to join? For future hosts, please reach out to Steve Jones via Twitter on @way0utwest. Just a heads up that there is a line of people who also want to host, so if you’re uncertain, do it anyway because you have time to prep!
  • Why host? Well, as a blogger, this is a wonderful way to ramp up your visualizations and to get another bloggers to know your work. Plus, it’s one way to give back to the community. Check out how great are the posts by looking into the previous topics.

I hope this is going to be fun and I’m definitely looking forward to reading your thoughts on my theme. Let’s get writing!

my very advanced drawing skills, as always