Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9069017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:19:17+00:00 2026-06-16T17:19:17+00:00

I know this has probably been asked a million times but I can’t find

  • 0

I know this has probably been asked a million times but I can’t find anything definite for me. I’m making a website involving users who can build a list of items. I’m wondering what would be the best way for store their items in an SQL table?

I’m thinking will I need to make a seperate table for each user since there I can’t see any way to store an array. I think this would be inefficient however.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:19:18+00:00Added an answer on June 16, 2026 at 5:19 pm

    Depending on what an “item” is, there seem to be two possible solutions:

    1. a one-to-many relationship between users and items
    2. a many-to-many relationship between users and items

    If a single item (such as a “book”) can be “assigned” to more than one user, it’s 2). If each item is unique and can only belong to a single user it’s 1).

    one-to-many relationship

    create table users
    (
       user_id    integer primary key not null,
       username   varchar(100) not null
    );
    
    create table items
    (
       item_id    integer primary key not null,
       user_id    integer not null references users(user_id),
       item_name  varchar(100) not null
    );
    

    many-to-many relationship:

    create table users
    (
       user_id    integer primary key not null,
       username   varchar(100) not null
    );
    
    create table items
    (
       item_id    integer primary key not null,
       item_name  varchar(100) not null
    );
    
    create table user_items
    (
        user_id   integer not null references users(user_id),
        item_id   integer not null references items(item_id)
    );
    

    Because of your extremely vague description, this is the best I can think of.

    There is no need to use an array or something similar. It seems you are new to database modelling, so you should read up about normalisation. Each time you think about “arrays” you are probably thinking about “tables” (or relations).

    Edit (just saw you mentioned MySQL):
    the above SQL will not create a foreign key constraint in MySQL (even though it will run without an error) due to MySQL’s stupid “I’m not telling you if I can’t do something” attitude. You need to define the foreign keys separately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this has been asked thousands of times but I just can't find
I know this has probably been asked before, but I can't find it with
I know this has probably been asked a million times, but how do I
I know this has probably been asked before but I can't find a specific
I know this has probably been asked before but I can't seem to find
I know this has been asked probably a thousand times, but I've been biting
I know this has been asked at least a thousand times but I can't
This probably has been asked before but all I can find are questions regarding
I know this has probably been asked 100 times, but I don't know the
I know that this has been asked a million times before, but nothing that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.