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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:36:56+00:00 2026-05-26T15:36:56+00:00

I am designing a website for a small business (landscaping, tree removal, etc) owned

  • 0

I am designing a website for a small business (landscaping, tree removal, etc) owned by a family member. It’s kind of a pet project.

The website will allow users to create an account and then request services, and will create the necessary invoices, but it will also allow my family member to enter invoices for orders not received through the website.

I am working on the database (MySQL), and this is currently what I have. Anything containing “User” is referring to online customers, and anything with Cust refers to non-online customers.

Basically what I am trying to do here is this:

An Invoice has a customer, business, or user (online-customer). An invoice also one or more InvoiceLines, and each InvoiceLine has a Service or Product.

I put users (online-customers) in separate table because it makes sense for a user to have a passwordhash and password salt (and possibly other things), but a customer added solely for records keeping shouldn’t have a password and things related to the website.

   ServicesAndProducts 
--------------------------
| ID INT (PK)            | 
| Name VARCHAR(50)       |  
| BasePrice DECIMAL(7,2) |
| ...                    |
--------------------------

   CustServicesProvided               UserServicesProvided
---------------------------       ---------------------------
| ID INT (PK)             |       | ID INT (PK)             |
| ServiceID INT (FK)      |       | ServiceID INT (FK)      |
| CustInvoiceID INT (FK)  |       | UserInvoiceID INT (FK)  |
| ...                     |       | ...                     |
---------------------------       ---------------------------

       CustInvoices                     UserInvoices
--------------------------        --------------------------
| ID INT (PK)            |        | ID INT (PK)            |
| CustomerID INT (FK)    |        | UserId INT (FK)        |
| ....                   |        | ....                   |
--------------------------        --------------------------

        Customers                           Users
--------------------------        ---------------------------
| ID INT (PK)            |        | ID INT (PK)             |
| Name VARCHAR(50))      |        | Name VARCHAR(50)        |
| BasePrice DECIMAL(7,2) |        | PasswordHash VARCHAR(50)|
| ...                    |        | PasswordSalt VARCHAR(50)|
--------------------------        | ...                     |
                                  ---------------------------

I also have another similar BusinessServicesProvided, BusinessInvoices, and Business because I want the foreign keys, and Businesses would have different fields than the other two.

My question is there a way that I can combine the Invoice Tables together, and combine the Services Provided Tables together, while still maintaining the three kinds of the foreign keys between the Invoice Table and Customers and Users (and Businesses)?

I thought of possibly adding a InvoiceType table, and then having a TypeID (FK) in The Invoice Table to indicate, but I don’t know how to maintain a foreign key between the Entity (Customer, Business, or User) and the Invoice. e.g:

   ServicesAndProducts 
--------------------------
| ID INT (PK)            | 
| Name VARCHAR(50)       |  
| BasePrice DECIMAL(7,2) |
| ...                    |
--------------------------

      ServicesProvided    
---------------------------
| ID INT (PK)             |
| ServiceID INT (FK)      |
| CustInvoiceID INT (FK)  |
| ...                     |
---------------------------

       Invoices                            InvoiceType
--------------------------        ---------------------------
| ID INT (PK)            |        | ID INT (PK)             |
| ForeignID INT (FK)     |        | Name VARCHAR(50)        |
| Invoice Type INT (FK)  |        |                         |
| ....                   |        |                         |
--------------------------        ---------------------------

        Customers                           Users
--------------------------        ---------------------------
| ID INT (PK)            |        | ID INT (PK)             |
| Name VARCHAR(50))      |        | Name VARCHAR(50)        |
| BasePrice DECIMAL(7,2) |        | PasswordHash VARCHAR(50)|
| ...                    |        | PasswordSalt VARCHAR(50)|
--------------------------        | ...                     |
                                  ---------------------------

I also considered having a trigger to create a new customer when a user is created, but I would also like for a customer to be able to view the Invoices/Services they have requested in the past.

This is my first time designing a database so any ideas are appreciated.

  • 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-26T15:36:57+00:00Added an answer on May 26, 2026 at 3:36 pm

    No, you cannot point a foreign key at primary keys in different tables, telling the database to find a matching record in one of the tables (furthermore, presumably the range of primary key values in the different tables could overlap, and then you might match two or more of the primary key tables).

    Your mistake is to create a whole new table to account for the differences between, for example, customers and users. Instead, create a single table with the common columns (probably called customer) and then separate tables with foreign keys back to the main table. Each table holds the columns for one of the sub-types of customers (on-line or flesh-and-blood).

    Same for the different kinds of invoices. One table holds common invoice information (most especially the primary key) and one or more auxiliary tables holds the information particular to a kind of invoice.

    This design is similar to class inheritance in object oriented programming.

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

Sidebar

Related Questions

I am designing a website that will provide continuing education courses via streaming video.
I am designing a small website using HTML + JSP. This is my first
I am designing a small website where user register and pay there monthly fee,
I'm currently designing a small website and I'd like to implement the forgot your
I'm designing a database that will be the backend for a marketplace website. There
I'm fairly new to jQuery and css, and I'm designing a small website mostly
I have this small problem with a website I'm designing. It's fairly over, but
I am designing a website that will upload video files in ASP.NET. The question
I am designing a website which will query a simple MySQL database using AJAX
I'm designing a small buiness's website, and I'm windering if I should use HTML5

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.