/supabase-tutorials

How to delete records in Supabase?

Learn how to delete records in Supabase with our step-by-step guide—from setting up your project and database table to installing the client and executing delete commands.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to delete records in Supabase?

 

Step 1: Set Up a Supabase Project

To get started with deleting records, you first need to have a Supabase project set up. If you haven't already done this, follow these steps to create a new project on Supabase:

  • Visit the Supabase website.
  • Log in to your account or sign up if you don't have one.
  • Click on the "New Project" button.
  • Fill in your project's details, such as project name and organization.
  • Choose a database password, as you will need it later.
  • Click "Create Project" and wait for Supabase to set it up.

 

Step 2: Navigate to the Supabase Dashboard

Once your project is up and running, navigate to the Supabase Dashboard for your project:

  • Go to your Supabase account.
  • Click on the project you set up in the previous step.

This will take you to the main dashboard for your project.

 

Step 3: Set Up Database Table

For deleting records, you need to have a database table in your project:

  • From the Supabase dashboard, click on the "Table Editor."
  • Create a new table by clicking on the "New Table" button.
  • Define the columns needed for your table. For example, let's create a table named users with columns id, name, and email.
  • Save your new table.

 

Step 4: Install Supabase Client in Your Application

To interact with your Supabase database, you'll use the Supabase client. Install the client in your application:

npm install @supabase/supabase-js

 

Step 5: Initialize Supabase Client

Initialize the Supabase client in your application code with your project's credentials:


import { createClient } from '@supabase/supabase-js'

// Replace with your Supabase API URL and Key
const supabaseUrl = 'https://xyzcompany.supabase.co'
const supabaseKey = 'public-anonymous-key'
const supabase = createClient(supabaseUrl, supabaseKey)

 

Step 6: Delete Records from Supabase Table

To delete records from a table, use the Supabase client to interact with your database:


async function deleteUser(userId) {
  const { data, error } = await supabase
    .from('users')
    .delete()
    .eq('id', userId)

  if (error) {
    console.error('Error deleting user:', error)
  } else {
    console.log('User deleted:', data)
  }
}

// Call the function with a specific user id
deleteUser(123)

 

Step 7: Verify Deletion via Supabase Dashboard

Finally, verify that the record has been deleted:

  • Go back to the Supabase Dashboard.
  • Navigate to "Table Editor."
  • Select the users table.
  • Check if the record with the specified id has been removed.

 

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022