-1

Given the following table:

Title    Session    Year     Credit
C21         2       2018       6
C21         3       2018       6
C21         4       2018       6
C21         2       2019       6
C21         3       2019       6
C21         4       2019       6
D22         2       2018       4 
D22         3       2018       4
D22         4       2018       4
D21         3       2019       4
D21         4       2019       4

With the relational schema : SUBJECT(title, session, year, credit)

Is it possible to normalize the above to 4NF?

The criteria to normalize to 4NF is that it need to meet BCNF and multiple value of B exists for a single value of A given A->B. I am having trouble understanding and applying the bold to the table.

My attempt:

The table have repeated attributes for session, year and credit. Based on the bold statement (and BCNF met), I will normalize it to 4NF

Title    Session   
C21         2   
C21         3      
C21         4    
D22         2  
D22         3   
D22         4  

Title    Year   
C21      2018  
C21      2019
D22      2018
D22      2019

Title    Credit 
C21        6  
D22        4    

I am conflicting on the 3 decomposed table though because the 3 attributes (session, year, credit) do not look like independent relation to title.

Can anyone advise?

user3118602
  • 553
  • 5
  • 19
  • Are you normalizing that value or a schema/variable that could hold that value? "4NF is that it need to meet BCNF and multiple value of B exists for a single value of A given A->B" That is not not clear or a definition of 4NF. Please find one in a textbook & apply it & ask a question when stuck. There's no point in continuing with this question because an answer is just to tell you to do that. Asking us to rewrite a textbook with a bespoke example is too broad. Also your attempt needs to refer to the definition or published algorithm as justification or what you did is unjustified. – philipxy Oct 19 '20 at 03:34
  • Re "is this right": Show the steps of your work following your reference/textbook, with justification--not all terms/notations are standard & we don't know exactly what algorithm/method you are following & we want to check your work but not redo it & we need your choices when a process allows them & otherwise we can't tell you where you went right or wrong & we don't want to rewrite your textbook. Please see [ask], hits googling 'stackexchange homework' & the voting arrow mouseover texts. If you're not sure it's right, ask 1 specific researched non-duplicate question re where you got stuck. – philipxy Oct 19 '20 at 06:07

2 Answers2

-1
-- Subject TITLE taught in year YEAR, session SESSION,
-- is worth CREDIT credits.
--
subject {TITLE, SESSION, YEAR, CREDIT}

Given the predicate, and the data sample, the obvious FD is TITLE -> CREDIT, so it is possible to decompose subject to:

r1 {TITLE, CREDIT}
r2 {TITLE, SESSION, YEAR}

When contemplating NFs, it is important to focus on predicates and constraints -- logic. Sample data is helpful, but rarely tells the whole story. A table is in a specific NF for any set of valid rows, empty set included.

Based on the data sample, it looks possible to decompose {TITLE, SESSION, YEAR} into {TITLE, SESSION} and {TITLE, YEAR}, as in your attempt. More formally, it looks as if the join dependency

* { {TITLE, SESSION}, {TITLE, YEAR} } holds.

Let's see if I can verbalize this:

If a (subject) title was taught in session, and a title was taught in a year, then that title was taught in that session in that year.

Does this make sense? Is it logical?

If this makes sense then your initial solution {TITLE, SESSION}, {TITLE, YEAR}, {TITLE, CREDIT} is correct. However, what will happen in 2020, 2021? The rule states that if title C21 is taught in year 2021, it must be in sessions 2,3,4. Is this correct?

School assignments are hard, you often have to guess what the teacher was thinking. Sometimes I wonder if they were thinking at all. Guessing constraints from a small data sample is an extremely bad idea.


Here is my suggestion, the way I see it:

  1. That join dependency does not hold.
  2. FD TITLE -> CREDIT holds.
-- Subject TITLE is worth CREDIT credits.
--
subject {TITLE, CREDIT}
     PK {TITLE}


-- Subject TITLE was taught in year YEAR, session SESSION.
--
subject_ys {TITLE, SESSION, YEAR}
        PK {TITLE, SESSION, YEAR}

Both of these are now in 6NF and therefore in: 5,4,BCNF,3,... That is if and only if I understand predicates and constraints properly. Take a look at this example.

Damir Sudarevic
  • 21,891
  • 3
  • 47
  • 71
  • Thanks Damir. Regarding FDs, isn't TITLE -> YEAR, SESSION one of the FDs too? Sorry if this is a silly question, relatively new and will like to get it right. – user3118602 Oct 19 '20 at 08:36
  • @user3118602 Loosely speaking FD `X->Y` means: if you know X, you know Y. There are multiple `{YEAR, SESSION}` for a given `TITLE` in your example, so no. – Damir Sudarevic Oct 19 '20 at 13:09
  • @user3118602 If you are interested in NFs and database design for your own personal/professional projects then take a look at: https://dba.stackexchange.com/questions/262601/need-help-with-bcnf-decomposition-problem/262793#262793 If you have to pass an exam, then do as you must to pass. – Damir Sudarevic Oct 19 '20 at 13:12
-2

Whenever you want to normalize data relationships, the first thing you do is list all of the relationships.

  • A subject has a title and credit hours.

  • A subject has multiple sessions.

  • A subject is taught in multiple years.

  • A session is in a single year.

So, let's start with a Subject table.

Subject 
-------
Subject ID
Subject Title
Subject Credit Hours

Subject ID is a blind autoincrementing integer primary key.

Looks good so far.

Now, let's create a Session table.

Session
-------
Session ID
Session Number
Session Year
Subject ID (FK)

Session ID is another blind autoincrementing integer primary key.

We can break the Session table down to remove the repeating session numbers by moving the Subject ID foreign key to a junction table.

Session
-------
Session ID
Session Number
Session Year

SubjectSession
--------------
SubjectSession ID
Subject ID
Session ID

Looks good so far. Let's fill the tables

Subject ID  |  Subject Title  |  Subject Credit Hours
----------------------------------------------------- 
         1  |       C21       |           6
         2  |       D21       |           4
         3  |       D22       |           4

Session ID  |  Session Number  |  Session Tear  
----------------------------------------------
         1  |         2        |      2018    
         2  |         3        |      2018   
         3  |         4        |      2018     
         4  |         2        |      2019      
         5  |         3        |      2019      
         6  |         4        |      2019   
       
SubjectSessionID  |  SybjectID  |  Session ID
---------------------------------------------
               1  |          1  |           1
               2  |          1  |           2
               3  |          1  |           3 
               4  |          1  |           4
               5  |          1  |           5
               6  |          1  |           6
               7  |          3  |           1
               8  |          3  |           2
               9  |          3  |           3
              10  |          2  |           5
              11  |          2  |           6

I don't think that the year needs to be broken out. It's part of what defines a session, even though it repeats.

I don't know if this is 4NF, but this is as normalized as I would make it.

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
  • It feels like it is up to how the relational schema is interpreted to do the normalization? – user3118602 Oct 18 '20 at 02:20
  • @user3118602: Yes. You have to get the correct relationships to get a somewhat correct normalization. – Gilbert Le Blanc Oct 18 '20 at 02:22
  • 1
    @user3118602: *"It feels like it is up to how the relational schema is interpreted to do the normalization?"* Yes. Normalization depends on what each column *means*. [See the end of this SO answer.](https://stackoverflow.com/a/62430448/562459) – Mike Sherrill 'Cat Recall' Oct 18 '20 at 14:11