![]() | |
#1
| |||
| |||
|
#2
| ||||
| ||||
|
|
Consider these 2 related tables: Books(ID, Title, Author) Authors(ID, Name, DOB) Now another entity 'Reviews' is being built up steadily over time, but the Reviews are of either Books OR Authors. How is this entity implemented in the relational database with one table: choice A: |
|
Reviews(ID, Author, Book, Comments) where one of the foreign keys Author or Book is always null, (breaking some normal form or other?) |
|
OR |
|
two tables: Reviews_Books(ID, Book, Comments) Reviews_Authors(ID, Author, Comments) TIA |
#3
| |||
| |||
|
|
"VisionSet" <spam (AT) ntlworld (DOT) com> wrote Consider these 2 related tables: Books(ID, Title, Author) Authors(ID, Name, DOB) Now another entity 'Reviews' is being built up steadily over time, but the Reviews are of either Books OR Authors. How is this entity implemented in the relational database with one table: choice A: Reviews(ID, Author, Book, Comments) where one of the foreign keys Author or Book is always null, (breaking some normal form or other?) Why do you think that breaks a normal form? |
#4
| |||
| |||
|
| "Ed prochak" <ed.prochak (AT) magicinterface (DOT) com> wrote in message news:4b5394b2.0308050636.4e7df87a (AT) posting (DOT) google.com... "VisionSet" <spam (AT) ntlworld (DOT) com> wrote in message news:<uiCXa.5218$yl6.3003 (AT) newsfep4-winn (DOT) server.ntli.net>... Consider these 2 related tables: Books(ID, Title, Author) Authors(ID, Name, DOB) Now another entity 'Reviews' is being built up steadily over time, but the Reviews are of either Books OR Authors. How is this entity implemented in the relational database with one table: choice A: Reviews(ID, Author, Book, Comments) where one of the foreign keys Author or Book is always null, (breaking some normal form or other?) Why do you think that breaks a normal form? Okay so reading a book it doesn't break any normal form, but I thought the general rule of thumb was null values were only advisable if data could logically fill that field value. |
#5
| |||
| |||
|
|
Books(ID, Title, Author) Authors(ID, Name, DOB) Reviews(ID, Author, Book, Comments) |
#6
| |||
| |||
|
|
Books(ID, Title, Author) Authors(ID, Name, DOB) Reviews(ID, Author, Book, Comments) If there's only ever one review per book and one review per author, then put the review in the Books or Authors table as a review field. Otherwise it's got to be two review tables. If you want to combine the reviews, then why not also combine the Books and Authors table: BooksAndAuthors(ID int, IsThisABook boolean, Comments varchar(255) , ......) In fact, why not put everything in one table. |
#7
| |||
| |||
|
|
Consider these 2 related tables: Books(ID, Title, Author_ID) Authors(ID, Name, DOB) Now another entity 'Reviews' is being built up steadily over time, but the Reviews are of either Books OR Authors. How is this entity implemented in the relational database with one table: Reviews(ID, Author_ID, Book_ID, Comments) where one of the foreign keys Author or Book is always null, [....] |
#8
| |||
| |||
|
|
"Bob Badour" <bbadour (AT) golden (DOT) net> wrote in message news:zvZXa.2087$%95.319506529 (AT) mantis (DOT) golden.net... "VisionSet" <spam (AT) ntlworld (DOT) com> wrote in message news:slWXa.6034$yl6.3583 (AT) newsfep4-winn (DOT) server.ntli.net... You were right the first time. NULL breaks 1NF and violates the information principle. eh 1NF states "No repeating fields or groups of fields" how has null got anything to do with that? |
#9
| |||
| |||
|
|
But I was referring to a multi-field key, in that case one (or more) fields [sic] can be null. |
#10
| |||
| |||
|
|
The part I don't understand is why we never required a PRIMARY KEY constraint on all tables. |
![]() |
| Thread Tools | |
| Display Modes | |
| |