SQL Editing in a Post-Atom Era: A Sublime Transition

Transitioning to Sublime Text for SQL editing? Equip it with SQLBeautifier to ease your SQL formatting tasks. Ideal for Udacity SQL course students who are seeking a maintained and reliable editor in the post-Atom era. Upgrade your SQL editing environment now!

SQL Editing in a Post-Atom Era: A Sublime Transition

Overview

With Atom phased out, many of us are on the lookout for a new tool to manage our SQL projects. Sublime Text emerges as a solid choice. It's powerful, straightforward, and has a range of features making SQL editing a breeze.

In this article, we'll walk through setting up Sublime Text for SQL editing. We'll explore useful plugins, and compare the transition from Atom to Sublime Text. Our goal is to find a workflow that feels right, where managing databases is both efficient and enjoyable.

Let's dive into setting up Sublime Text, exploring its offerings for SQL editing, and ensuring a smooth transition in our post-Atom SQL adventures.


Setting Up the New Environment

Transitioning to a new text editor can feel like moving into a new home. It's all about setting it up to your liking.

After downloading and installing Sublime Text from the official website. We should do some SQL specific configuration to help us write well-formatted SQL code.

1. Install Package Control:

  • Install Package Control to manage plugins efficiently.
  • Press Ctrl+Shift+P (or Cmd+Shift+P on Mac), type Install Package Control, and press Enter.

2. SQL-Specific Plugins:

  • Again press Ctrl+Shift+P, type Install Package, then press Enter.
  • Search for and install plugins like SqlBeautifier, and any others that suit your workflow.
  • Later will use SqlBeautifier, in other articles will explore other interesting plug ins.

Now, your Sublime Text environment is ready for SQL editing. The setup is straightforward, and with a few plugins, you'll enhance your SQL workflow significantly. Up next, we'll delve deeper into leveraging Sublime Text features for an efficient SQL editing experience.


The Significance of Formatting

A well-formatted SQL script not only looks appealing but also fosters comprehension and maintenance. When we glance through a script, our eyes follow a pattern. Consistent formatting aligns with this pattern, easing the process of code review and bug identification.

Just picture a script with inconsistent indentations, a myriad of coding styles, or lacking spacing. It's akin to navigating a labyrinth. On the flip side, a well-structured script is like a well-laid out map, guiding you through the logic seamlessly.

Formatting isn't about being pedantic or catering to a particular aesthetic. It's about creating a conducive environment for collaboration and understanding among developers. And remember, a well-formatted script is a reflection of a meticulous developer.

For example, compare the following:

select Rental_month,
Rental_year,
  storeid,
    rental_count
FROM (
SELECT sr.store_id storeid,
DATE_PART('month',rental_date) AS Rental_month,
  DATE_PART('year',rental_date) AS Rental_year,
COUNT(r.rental_id) AS rental_count
    from store sr
    JOIN staff sf
ON sr.store_id = sf.store_id
JOIN payment p
ON sf.staff_id = p.staff_id
JOIN rental r
ON r.rental_id = p.rental_id
GROUP BY 1,2,3) t1
ORDER BY 2;

Keywords are hard to see because of the variable names being having inconsistent casing. The same applies to the field and function names.

Indentation is also important. It should help us easily locate the different sections of the query, but we have to read and understand the query to identify its sections in this example.

In contrast, a properly formatted query is easier to read:

SELECT
    rental_month,
    rental_year,
    storeid,
    rental_count
FROM (
    SELECT
        sr.store_id storeid,
        date_part('month', rental_date) AS rental_month,
        date_part('year', rental_date) AS rental_year,
        count(r.rental_id) AS rental_count
    FROM
        store sr
        JOIN staff sf ON sr.store_id = sf.store_id
        JOIN payment p ON sf.staff_id = p.staff_id
        JOIN rental r ON r.rental_id = p.rental_id
    GROUP BY
        1,
        2,
        3) t1
ORDER BY
    2;

The subquery is trivial to locate. The different sections of the outer query are easy to identify thanks to the keywords being all uppercase and being indented at the start of the row. In contrast, the subquery ones are indented further.


How should we format our SQL code?

Each programming language community has some base formatting guidelines that can be tweak by each team to meet their purposes better.

The formatting of SQL could vary, but some characteristics are almost universally accepted and practiced.

  • Keywords and function names should be written in uppercase.
  • Field names and aliases should be written in lower case.
  • Use indentation to differentiate Subqueries, CTEs, and in general, the sections of the query.

A widely referenced style guide list more important parts of the style; we should be mindful that this could vary between SQL communities or development teams.


Streamlining SQL Formatting with SQLBeautifier

Formatting is crucial for readable and maintainable code. Sublime Text, armed with the SQLBeautifier plugin, automates this chore.

  1. Save your file with a .sql extension to activate SQL-specific features.
  1. Use the shortcut CMD + K, CMD + F on Mac or Ctrl + K, Ctrl + F on Windows/Linux to format your code. Alternatively, open the command palette with CMD + Shift + P (or Ctrl + Shift + P), type "Format Current SQL File", and hit Enter.

Auto-formatting with SQLBeautifier keeps your SQL code clean and consistent, allowing you to focus on the logic rather than the formatting.


Wrapping Up

Transitioning to a new text editor for SQL can feel like a chore, but it's a necessary step to ensure a reliable and maintained workspace. With plugins like SQLBeautifier, setting up a conducive environment for SQL editing is a breeze. 

Embrace the transition, explore the features your new editor offers, and continue honing your SQL skills in a modern setup!


Addendum: A Special Note for Our Readers

I decided to delay the introduction of subscriptions, you can read the full story here.

In the meantime, I decided to accept donations.

If you can afford it, please consider donating:

Every donation helps me offset the running costs of the site and an unexpected tax bill. Any amount is greatly appreciated.

Also, if you are looking to buy some Swag, please visit I invite you to visit the TuringTacoTales Store on Redbubble.

Take a look, maybe you can find something you like: