Visual Basic Database Tutorial - Part 5, Page 5
Don't know about you, but most of my programming never works first time. In fact, most of it just never works. But I've a good feeling about this database design... and it's not just 'cause I spent hours testing it.
So let's put our database design through the works. First off, let's enter a new owner into the Owners table.
Open it up and throw in a little sample information. Here's mine:
Note that I've been automatically assigned a unique OwnerID of 1.
BRILLIANT! That's our Primary Key stepping in.
Now open up our Pets table and enter a little more sample information. But this time, enter number 15 in the OwnerID field. In other words, you're saying this pet belongs to the non-existent owner number 15.
When you try to move off the record, you should receive the following groan:
Or in other words, "You can't add a pet without it having an owner, you crazy crazy crazy person!"
Try changing the OwnerID to 1 and adding the pet once more.
Does it work? Bravo!!
Try adding all my pets to your list; the three iguanas Wiggles, Green Thing and Strangely Brown, and that 48 year old cow, Daisy.
It's worth noting that you won't be able to put anything but a number in the OwnerID field. When we designed the table, we choose the 'Number' data type which protects it from strange dates, bits of horrid text or weird boolean values. Groovy!
OK go back to the Owners table and try to add another record. You'll notice the OwnerID number is automatically incremented...
... and you should now be allowed to add entries to the Pets table using that newly-generated OwnerID number.
Hurrah! Go on... shout hurrah!!
Page 5 of 6