Here is a fundamental database design question. I have learnt that one of the elements of good database design is to avoid redundancy by creating more tables and referencing them using foreign keys. The query I have then is what is the procedure of data entry? Take a look at this example:
Instead of having this:
tblBooks
BookID, Title, Author
1, Mastering Access, Antony
2, SQL Basics, John
3, Intro to Computers, Anthony
I have
tblBooks
BookID, Title, AuthorID
1, Mastering Access, 1
2, SQL Basics, 2
3, Intro to Computers, 1
and
tblAuthors
AuthorID, Name
1, Antony
2, John
This looks good and is better design because only authorID (not author name) is repeated in tblBooks. However, how do I now enter the data for a particular book? If referential intrigty is enforced, tblBooks does not accept AuthorID unless the record already exists in tblAuthors. If not then entering the authorID makes no sense and you don�t have it since it�s a foreign key. Someone please clarify.
Instead of having this:
tblBooks
BookID, Title, Author
1, Mastering Access, Antony
2, SQL Basics, John
3, Intro to Computers, Anthony
I have
tblBooks
BookID, Title, AuthorID
1, Mastering Access, 1
2, SQL Basics, 2
3, Intro to Computers, 1
and
tblAuthors
AuthorID, Name
1, Antony
2, John
This looks good and is better design because only authorID (not author name) is repeated in tblBooks. However, how do I now enter the data for a particular book? If referential intrigty is enforced, tblBooks does not accept AuthorID unless the record already exists in tblAuthors. If not then entering the authorID makes no sense and you don�t have it since it�s a foreign key. Someone please clarify.