Do You Want to Learn SQL?

Take our free eight day course, where I'll teach you in simple to understand English all you need to get started learning SQL.

-
DAYS
-
HOURS
-
MINUTES
-
SECONDS

Free Beginners SQL Course!

Automatically Format Your SQL

·

·

,

Hey, welcome back to another SQL Minute. Today we’re going to learn how to code like a boss by delving into formatting your code. Now, some of you may have some rules you use to format code. Others may just type it out and wonder how they should format it.

What I’m going to do today is show you a really cool trick.

First of all, let’s look at why it’s important to format code. So what I’ve done here is put on the screen in a mean way, unformatted SQL.

And it will run.

If you look closely here, you’ll see there’s actually a subquery buried in. So if I needed to troubleshoot this, it’d be really tough because it’s not formatted.

Now, I could go through by hand and essentially format this to a way to make it easier. But if it’s a very long SQL, that can take time, and who needs to spend time on something that you could do automatically?

So what I want to show you is how to use an automatic formatting tool to take care of this. So let me pull that up right now. And what I’m bringing in here is the online format from Apex.

And if I paste in my code here, as you can see, it took some time, it spun, and it actually now just formatted it. And behind the scenes here, when I click on formatted, you can see the code. So I will put in the comments this URL for the formatter. And let’s try this formatted code now to see if it can work in my SQL. So there’s the formatted code.

Obviously, much easier to read. There’s the sub query now broken out. And let’s run it. And there it is, we can run. So this is a really cool tool and I hope you like it.

I’ll catch you in the next episode.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Table Of Contents

Add a header to begin generating the table of contents

More from the blog


MySQL PostgreSQL SQLite SQL Server