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.

The Database Forum


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



Reply
perhaps a dumb question
Old 11-27-2008, 08:56 AM perhaps a dumb question
Banned

Posts: 34
Trades: 0
helo.I am building quite a huge site, with mysql. at the moment my tables are linked by their id, like tblproduct will have productid and businessid, so my question is is there a huge benefit to using foreign keys? and how do I use them?
Necaxa is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-27-2008, 10:10 AM Re: perhaps a dumb question
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Just as a notice: in mysql, foreign key are only enforced when you use an innodb table format, which is not the default, so if you have a shared hosting somewher (you are not the person taking care of the server), you probably don't have them.

Now for the generic theory...
An foreign key is a constraint that you put on a field, that basically means "I wanot only something in this field that already exists in the table x on the field y".
It enforces, for example, that when you create an invoice, the corresponding user is already existing in the db.
If it was not the case, the DB would return an error saying that the given userId is not found in the user list.

I haven't done mysql in years, but the syntax is generally something along those lines:
Code:
create table other_table(
  id integer
)
create table example(
  id interger not null,
  fk integer not null reference other_table(id)
);
__________________
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!
 
Old 11-30-2008, 09:19 AM Re: perhaps a dumb question
Novice Talker

Posts: 5
Name: Edy Galantzan
Trades: 0
Use

CREATE TABLE name (
....
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
__________________
Edy

Web Pro
edygalantzan is offline
Reply With Quote
View Public Profile Visit edygalantzan's homepage!
 
Reply     « Reply to perhaps a dumb question
 

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.18014 seconds with 12 queries