We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,894 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

dont understand f-key

let say i have two tables called user and cart

user-table
id    username    password
1     dave        dave
2     dan         dan


cart-table
id    user-id   item_name   
1     2         car
2     2         table
3     1         laptop

now i understand that bother id's will be primary key.
i can also create user-id f-key bc its same as id from user.

but i dont understand the need for f-key. lets say i need to see who brought a car.

cant i just get user-id from cart. than look at id from user table and see the username?
does f-key some how makes it easier?

iam new to f-key

4
Contributors
3
Replies
1 Day
Discussion Span
5 Months Ago
Last Updated
4
Views
hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 7

I guess you mean foreign key by f-key.

you table structure shows u already using f-key in your cart-table. Here your user_id column in cart-table is f-key because it refers to id column of user-table.

so I am not able to understand why u are confused?

urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24

cant i just get user-id from cart. than look at id from user table and see the username?

Yep, that's exactly how a foreign key is used! "Foreign key" is just a fancy way of saying it, that's all.

GhostWolf
Newbie Poster
13 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You can use a foreign key to prevent inserting a non-existent user-id into your table.

pritaeas
Posting Prodigy
Moderator
9,268 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,457
Skill Endorsements: 86

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0635 seconds using 2.63MB