Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
database question Primary Key and Foreign Key
Old 04-05-2010, 09:53 PM database question Primary Key and Foreign Key
millwalll's Avatar
Webmaster Talker

Posts: 674
Name: James
Location: KENT
Trades: 3
Hi all,

I am a little confussed I have not done Datbase in ages and just want to clear somthing up.

if you have table that has primary key let say
transactionID waht auto increment

Then you have another table that use this as a foreign key am I right in thinking that it should get the value from the first table and store it into the second one?

so lets say
table one
transaction id = 10
name = blar

table two
id = 1
transaction id =10
address = blar blar

that way you can link everything together with the transaction ID

thanks in advance
__________________

Please login or register to view this content. Registration is FREE
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
 
Register now for full access!
Old 04-06-2010, 02:52 AM Re: database question Primary Key and Foreign Key
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Yep, it's (almost) that.
The foreign key enforces that the value you put in table2 must exists in table1 at the moment of the insert.

So no, it don't get the value or copy it from table1.
You provide it upon inserting/updating, and the db check at that time it's there in the parent table.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to database question Primary Key and Foreign Key
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09778 seconds with 12 queries