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 6205701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:19:16+00:00 2026-05-24T05:19:16+00:00

I am in the process of setting up tables in my database for my

  • 0

I am in the process of setting up tables in my database for my first project. (Exciting!)

I am having a hard time deciding what types of relationships I need to set up.

I have the following basic tables planned.

products
-----
id
product_name
product_details
product_url
product_img
category_id
business_id


categories
-----
id
category_name
category_description
category_slug


businesses
----------------
id
business_name
business_phone
business_address
business_city
state_id
business_zip

state
-----
id
state_name

Where I am stuck is deciding what types of relationships to set up.

Each product can only belong to 1 category, and can only belong to 1 business

As for the business table I am wondering if its a better idea to break out the city and zip-code into separate tables.

I want to be able to retrieve products by category and city ,
For example: ‘shoes’ in ‘los angeles’, or just ‘shoes’ or all products in ‘los angeles’

Can anyone offer some insight or share their experience. Since I am getting ready to set up my tables I’d rather work out those scenarios now then half way through development.

  • 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-05-24T05:19:17+00:00Added an answer on May 24, 2026 at 5:19 am

    Your design is OK – it’s pretty clean. I can’t see a many-to-many anywhere – it seems to be a straight hierarchy.

    Also, your thinking process seems clear – keep asking yourself these kinds of questions and you’ll be fine.

    However, I have these suggestions:

    Firstly, always name your tables in the singular, business not businesses.

    Secondly, try to avoid prefixing the table name to column names, so name, not business_name – when you reference it in a query, it’s obvious anyway: business.name (the extra business_ in business.business_name is redundant)

    Also, because zip is in a city, and city is in a state, storing city and state on business is redundant data, so you should probably do this:

    business
    ----------------
    id
    name
    phone
    address
    zip_code_id
    
    zip_code
    --------
    id
    city_id
    name
    
    city
    ----
    id
    state_id
    name
    
    state
    -----
    id
    name
    

    To answer your questions re queries, you can get what you need with this schema. I won’t post it here unless you really have trouble, but they are very simple queries, so I’ll leave that for you to work out.

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

Sidebar

Related Questions

I'm setting up a standalone Java service with an in-process, in-memory HSQL database. Persistence.xml
I'm setting all fields to nullable types where the back-end database fields they correspond
Im in the process of setting up a database of CCG cards. Each card
I have a project here that connects to an in-production database and grabs tables
We are in the process of setting up a new development environment for about
I am in the process of setting up a server to run a Ruby
I'm currently in the process of setting my website, largely with php. Though this
I'm currently in the process of setting up a media server for my dorm
I'm new to Ruby on Rails, and I'm in the process of setting it
I'm in the process of setting up a system which will have to repeatedly

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.