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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:54:52+00:00 2026-06-11T10:54:52+00:00

I’m building a database table representing a ‘note’ that has a parent-child relationship in

  • 0

I’m building a database table representing a ‘note’ that has a parent-child relationship in two of it’s columns, like so:

ID           INT(10) PK NOT NULL UNSIGNED ZEROFILL AUTOINCREMENT  -- Primary key
parent_ID    INT(10) UNSIGNED ZEROFILL                 -- References Primary key
username     VARCHAR(30) NOT NULL
information  VARCHAR(256) NOT NULL
comment      VARCHAR(256) NOT NULL

where username is a foreign key to a user table and is the username of the person who wrote the note, information is the information contained in the note and comment is what username added. comment will always have something in it, and is not necessarily the same as the previous user.

The concept is that someone can “copy” a note and have their own comments, and say “I got this note from xxx”, hence the parent-child relationship. A bit like sharing in facebook, perhaps.

How do I correctly form the parent_ID column? Should I use an identifying relationship; which sides are mandatory?
I figure this has to be a 1-to-Many relationship since five people can copy the same note.

I expect there to be more copying than creating new notes, so there will be a relatively small number of NULL‘s in the records, but to get rid of nulls entirely should I apply a NOT NULL constraint and simply make the default parent 0 with an essentially meaningless record at ID 0 and take note of this in the software?

Is this even the correct way? Should I employ a two-table system with:

ID          INT(10)      PK
information VARCHAR(256)
orig_user   VARHCAR(30)  FK  -- Potentially

and

ID          INT(10)      PK FK
username    VARCHAR(30)  PK FK
comment     VARCHAR(256)

Which eliminates any possible NULL‘s by definiton?

Thanks

  • 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-11T10:54:53+00:00Added an answer on June 11, 2026 at 10:54 am

    Should I use an identifying relationship

    No, only ID should be in PK since it alone is unique. Also, a root (parent-less) note will have a NULL parent_ID and NULLs cannot be in PK.

    I figure this has to be a 1-to-Many relationship since five people can copy the same note.

    Correct. It’s also a tree, since there can be multiple levels of copying.

    … should I apply a NOT NULL constraint and simply make the default parent 0 with an essentially meaningless record at ID 0 and take note of this in the software?

    No need, FK would still be enforced on 0 and you’d need a “dummy” row just to satisfy it, as you already noted. FK ignores NULLs, so just put a NULL in the root note’s parent_ID.

    Should I employ a two-table system…

    This doesn’t model the same thing. It just allows you to connect to the original user, but not original note.

    A different two-table design would be viable if a single note could have multiple parents, but that doesn’t seem to be the case here.

    Which eliminates any possible NULL’s by definiton?

    You seem very intent on eliminating NULLs. Any reason for that?


    All in all, you should store notes in just one table, like this:

    CREATE TABLE note (
        ID           INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
        parent_ID    INT(10) UNSIGNED,
        username     VARCHAR(30) NOT NULL,
        information  VARCHAR(256) NOT NULL,
        comment      VARCHAR(256) NOT NULL,
        FOREIGN KEY (parent_ID) REFERENCES note (ID),
        FOREIGN KEY (username) REFERENCES `user` (username)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
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
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into

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.