Search code examples
databasedatabase-designnormalizationdatabase-normalization

Normalization a table


I want to normalize this table to 3NF

              -----------------------------------
              |        |         |              |
              |        V         V              V
----------------------------------------------------------------------------------------------------------
|user_name|post_id|post_title|post_text|post_submitted_time|comment_id|comment_text|submited_comment_time|
----------------------------------------------------------------------------------------------------------
     |        |                                                  ^            ^                ^
     |        |                                                  |            |                |
     -------------------------------------------------------------------------------------------

How I can do this Work?


Solution

  • Assuming user_name is a PK.

    ------------------------------------------------------------
    |post_id|post_title|post_text|post_submitted_time|user_name|
    ------------------------------------------------------------
         1      foo       bar          08:15             baz  
    
    ------------------------------------------------------------------
    |comment_id|comment_text|submitted_comment_time|user_name|post_id|
    ------------------------------------------------------------------
         1         blabla          13:37             anyname     1
         2         foobar          13:38             anyname     1