© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
7 replies
Shivansh

How do I create separate tables for each user in the database??

Hi,
I want to have separate tables for each user, is this possible and how can I implement this?

I asked supabase AI and it gave me this answer

how can I automatically create separate tables for each user
To automatically create separate tables for each user, you can use row level security (RLS) policies. With RLS policies, you can restrict access to specific rows in a table based on the user who is accessing the data.

Here's an example of how to create a table with RLS policies:

create table private_data (
  id uuid not null,
  user_id uuid not null,
  data text,
  primary key (id)
);

alter table private_data enable row level security;

create policy private_data_policy on private_data for select using (auth.uid() = user_id);

In this example, we create a table called private_data with columns for id, user_id, and data. We then enable row level security on the table using the alter table command. Finally, we create a policy called private_data_policy that restricts access to rows in the private_data table based on the user_id column.

With this policy in place, each user will only be able to access rows in the private_data table where their user_id matches the auth.uid() value of the user making the request.

Note that you will need to create a new table for each user, or modify the user_id column in an existing table to use RLS policies.
how can I automatically create separate tables for each user
To automatically create separate tables for each user, you can use row level security (RLS) policies. With RLS policies, you can restrict access to specific rows in a table based on the user who is accessing the data.

Here's an example of how to create a table with RLS policies:

create table private_data (
  id uuid not null,
  user_id uuid not null,
  data text,
  primary key (id)
);

alter table private_data enable row level security;

create policy private_data_policy on private_data for select using (auth.uid() = user_id);

In this example, we create a table called private_data with columns for id, user_id, and data. We then enable row level security on the table using the alter table command. Finally, we create a policy called private_data_policy that restricts access to rows in the private_data table based on the user_id column.

With this policy in place, each user will only be able to access rows in the private_data table where their user_id matches the auth.uid() value of the user making the request.

Note that you will need to create a new table for each user, or modify the user_id column in an existing table to use RLS policies.
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Can I create a separate user for ready-only access to the database?
SupabaseSSupabase / help-and-questions
4y ago
How to create a bucket folder for each user in the profiles table?
SupabaseSSupabase / help-and-questions
4y ago
Missing tables in database
SupabaseSSupabase / help-and-questions
2mo ago
Create rows in multiple tables on new user
SupabaseSSupabase / help-and-questions
4y ago