LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-13-2011, 07:05 PM   #1
shadow771
LQ Newbie
 
Registered: Jan 2009
Location: Egypt/Alexandria
Distribution: not yet..
Posts: 17

Rep: Reputation: 2
Table relations in MySQL


Hello,
I'm trying to join two tables for
MySQL Syntax (Toggle Plain Text)
Code:
www.cs75.net
project 2 (users, history), but i
read that JOIN isn't a good practice and will eventually be bad if
your tables get larger.
so i created new tables as the following:
Code:
http://pastebin.com/MBzCM1Wv
used a foreign key.
the question now am i on the right track?
is JOIN real problematic with larger tables?
is FK any better than JOIN?

another method my friend pointed me to but its also condusing:
Code:
http://pastebin.com/ukidpCTP
he doesn't join or use a FK but he told me to use php to fill everything because table relations are slow...

I am really confused about MySQL i don't know how to design my tables. is there any reliable book or source to learn from other than the MySQL manual cause i am a beginner and the manual isn't friendly...

Thanks in advance.
 
Old 05-13-2011, 10:31 PM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Mostly difficult to really quantify in practice. Also are you comparing apples with oranges?

FK is a relational construct(DDL/Model) while Joins are a way to fetch the data (DML/View).

In good implementation, you would use FK with joins. Using FK would ensure that the data is consistent even if specific application programs don't validate it).

Thus, I wouldn't reccmmend the third suggestion (using php - or any other program - for this task).

OK?
 
1 members found this post helpful.
Old 05-14-2011, 12:01 AM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,224

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by shadow771 View Post
is FK any better than JOIN?
I think you're confused. You're going to need a join to actually get the data out of the database. You use the foreign key to keep the data consistent as it's being modified.

Quote:
I read that JOIN isn't a good practice and will eventually be bad if your tables get larger.
As a rule, the statement that "Join isn't a good practise" is wrong.

Breaking up tables to minimize the amount of duplicate data you're storing is called normalization and is normally a good practise, even though it increases the number of joins required.

It's true that denormalizating is the the right thing for some applications, but there are tradeoffs to this and it certainly isn't automatically the right choice.

Quote:
he doesn't join or use a FK but he told me to use php to fill everything because table relations are slow...
Sorry to be honest here, but that's one of the most stupid things I've ever read. Do you think that the carefully performance-tuned database system just might be faster than something he can knock up in PHP? He's probably using an O(n^2) algorithm to join the tables (comparing each row in one table to each row in the other table) in PHP too.

As for books on database design, this one is not bad at all:

http://www.apress.com/9781590597699

And here's a good book on SQL:

http://www.amazon.com/dp/0321118030

Last edited by dugan; 05-14-2011 at 01:08 AM.
 
1 members found this post helpful.
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql 'Table 'mysql.user' doesn't exist' Joe of Loath Linux - Server 13 08-05-2010 06:54 AM
MySQL db table tommytomato Linux - General 10 08-24-2004 05:57 AM
MySQL non-realtime table-by-table mirroring Passive Linux - Software 1 01-20-2004 12:11 PM
How to import MS ACCESS Table including OLE filed into the MySQL Table ? myunicom Linux - General 1 11-28-2003 11:30 AM
deleted mysql table in mysql now cant do anything nakkaya Linux - Software 0 03-18-2003 06:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration