Skip to content
Advertisement

is it violate 2NF?

My table

book

  • PK ID INT
  • pfK langID INT
  • title VARCHAR
  • description MEDIUMTEXT
  • releaseYear YEAR
  • chaptersPrice DOUBLE
  • thumbnail BLOB

Where pfk – Primary-Foreign Key;

{ID, langID} – PK;

chaptersPrice – price of each chapter of book. Example:

BookName1:

  • chaptersPrice=2

BookName2:

  • chaptersPrice=3

I think in this table some attributes are functionally dependent on the part of primary key (ID):

{ID} -> {releaseYear}

{ID} -> {chaptersPrice}

{ID} -> {thumbnail}

Should I implement it like this

book

  • PK bookID
  • pfK langID
  • title
  • description

book_attrs

  • PK ID
  • FK bookID
  • releaseYear
  • chaptersPrice
  • thumbnail

Then book and book_attrs have “one-to-many” relationship

Advertisement

Answer

Some considerations may depend on your use-case / domain model.

  • releaseYear of a book typically does not change (in simple cases), so it could be in BOOK table.

  • From a ‘book store’ perspective, ‘price’ could be in a different table, as that would be updated based on market conditions.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement