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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:40:04+00:00 2026-05-17T02:40:04+00:00

I’m fairly new to database design, but I understand the fundamentals. I’m creating a

  • 0

I’m fairly new to database design, but I understand the fundamentals. I’m creating a relational database and I’d like to do something similar to creating a reusable type or class. For example, let’s say I have a Customer table and a Item table. Customer and Item are related by a standard 1-to-many relationship, so Item has a column called CustomerId.

I’d also like to have multiple “notes” for each Customer and each Item. In an normal OOP model, I’d just create a Note class and create instances of that whenever I needed. Of course, a relational database is different. I was thinking about having a Note table, and I’d like a 1-to-many relationship between Customer and Note, as well as Item and Note. The problem then is that the Note table will have to have a column for each other table that wishes to use this “type”. (see example below)
note_relation1

I also thought that instead, I could create an intermediate table between Note and Customer/Item (or others). This would allow me to avoid having extra columns in Note for each table referencing it, so note could remain unchanged as I add more tables that require notes. I’m thinking that this is the better solution. (see example)
note_relation2

How is this sort of situation usually handled? Am I close to correct? I’d appreciate any advice on how to design my database to have the sort of functionality I’ve described above.

  • 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-17T02:40:04+00:00Added an answer on May 17, 2026 at 2:40 am

    Yes, your concluding example is correct, and should be the way to go.

    You model a “complex type” in relational databases by creating tables. You can consider the table as a class: in fact ORM solutions often map a class directly to a table. An instance of the custom type is a row in its table, and the instance can be referenced by the value of the primary key.

    You can use your custom “complex type” for fields in other tables by using the same data type as the primary key of the “complex type”, and enforcing the relationship with a foreign key constraint:

    Let’s build a complex type for “countries”:

    CREATE TABLE countries (
       iso_code     char(2)       NOT NULL,    
       name         varchar(100)  NOT NULL,
       population   bigint       
       PRIMARY KEY (iso_code)
    );
    

    And let’s add a couple of “country” instances:

    INSERT INTO countries VALUES ('IE', 'Republic of Ireland', 4470700);
    INSERT INTO countries VALUES ('US', 'United States of America', 310403000);
    

    Now we’re going to use our complex “countries” type in a “users” table:

    CREATE TABLE users (
       id          int            NOT NULL,    -- primitive type
       name        varchar(50)    NOT NULL,    -- primitive type
       age         int,                        -- primitive type
       country     char(2),                    -- complex type
       PRIMARY KEY (id),
       FOREIGN KEY (country) REFERENCES countries (iso_code)
    );
    

    With the above model, we are guaranteed that the country field of the users table can only be a valid country, and nothing but a valid country.

    In addition, using a junction table, as you suggested, is also a suitable approach to deal with that kind of polymorphic relationship. You may be interested in checking out the following Stack Overflow posts for some further reading on this topic:

    • How can you represent inheritance in a database?
    • Possible to do a MySQL foreign key to one of two possible tables?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Seemingly simple, but I cannot find anything relevant on the web. What is the
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.