Sorry for the late response... Foreign keys are used to establish a relationship between tables. We can then get at information stored in related tables by matching the primary key of one table to the foreign key of another related table.
With that in mind, a classic table join query would look something like this: SELECT Customer.name, Order.date, Order.total FROM Customer INNER JOIN Order ON (Customer.customer_id = Order.customer_id) Here the FROM clause contains the table join. Order.customer_id is the foreign key in the Order table that matches Customer.customer_id, the primary key in the Customer table. So the use of foreign keys is simply a way to link records in one table to records in another table. ----- Original Message ----- From: "Michael Kear" <[EMAIL PROTECTED]> To: "SQL" <[EMAIL PROTECTED]> Sent: Friday, September 27, 2002 10:54 AM Subject: Why External keys? > Sorry if this is such a basic question as to be stupid, but why do you > sometimes have foreign keys? I've looked at MS's Books Online, but that > only tells me how to do it, not why I'd want to, which is typical of > Microsoft's documentation. > > > On my tables in MS SQL2000, I typically have an primary key ID field which > is int, identity, 1, 1 which works fine as far as I've gone, which I'll > admit isn't all that advanced. > > > There is obviously an advantage to having a foreign key, because people do > it, but I'm afraid I am too much a learner to know what the advantage is. > > > Can someone give me a quick explanation of why and/or when its better not to > have the key as a field in the table itself? > > > Cheers, > Mike Kear > Windsor, NSW, Australia > AFP WebWorks > > > ______________________________________________________________________ Get the mailserver that powers this list at http://www.coolfusion.com Archives: http://www.mail-archive.com/[email protected]/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
