Write and execute SQL queries in Supabase's SQL editor. Follow our step-by-step guide to set up your project, explore the interface, and format your code.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Set Up Your Supabase Project
Go to the Supabase website and sign in to your account.
On the dashboard, click on New Project
to create a new Supabase Project.
Fill in the necessary details like Project Name
, Database Password
, and Region
.
Click on Create New Project
. Wait for the project to be set up, which may take a few minutes.
Step 2: Access the Supabase SQL Editor
Once your project is created, navigate to the project dashboard.
In the left-hand menu, click on SQL Editor
. This will open the SQL editor interface.
Step 3: Understanding the SQL Editor Interface
The SQL editor consists of a query input area where you write SQL queries.
Below the query input area, you'll find options like Run
, Save
, and Format SQL
.
To the left, you will find a Schemas
tab to explore tables and database objects.
Step 4: Writing Your First SQL Query
Ensure that you have some tables created in your database. For this example, let's assume a table named users
.
To select all entries from the users
table, enter the following SQL query in the editor:
SELECT \* FROM users;
Click the Run
button to execute the query.
Observe the results in the Results
pane below the query editor.
Step 5: Writing More Complex Queries
To filter users with a specific condition, you can use a WHERE
clause:
SELECT \* FROM users WHERE age > 30;
For ordering the results, add an ORDER BY
clause:
SELECT \* FROM users ORDER BY age DESC;
To join another table, say orders
, with users
, use a JOIN
statement:
SELECT users.name, orders.item FROM users
JOIN orders ON users.id = orders.user\_id;
Step 6: Saving and Managing Queries
After writing a query, you can save it for future use.
Click on the Save
button, and you will be prompted to name your query.
Your saved queries can be accessed from the Saved Queries
tab.
Step 7: Exploring Your Database
Use the Schemas
tab to explore tables, views, and functions.
Click on any table to view columns and existing rows.
Use this information to inform your query writing process.
Step 8: Formatting Your SQL Code
To keep your SQL code readable and well-organized, click the Format SQL
button after writing your query.
This will automatically format your SQL code according to best practices.
By following these detailed steps, you can efficiently write and manage SQL queries within the Supabase SQL editor, taking full advantage of its intuitive interface and powerful features.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.