SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 4th, 2003, 02:26 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
MySQL > Linking tables?

I'm going crazy here... reasonably simple concept... however i have three books open, the MySQL manual and numerous webpages... can't seem to find any reference on how to add foreign keys...

have yet to see anything that says you can't (quite frankly, what's a database without foreign keys??)...

help me out before i pop a vein... =)

thanks

Reply With Quote
  #2  
Old March 4th, 2003, 07:33 PM
ctownsen357 ctownsen357 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 1 ctownsen357 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Make sure you are set up to use InnoDB table type and have specified in your SQL statement that you want to make the table an InnoDB table. Additionally the columns that are foreign keys need to be indexes as well.

Like this:

CREATE TABLE `some_table` (
`Some_Code1` bigint(20) NOT NULL default '0',
`Some_Code2` bigint(20) NOT NULL auto_increment,
`Field_Name` varchar(100) NOT NULL default '',
PRIMARY KEY (`Some_Code1`,`Some_Code2`),
KEY `some_table_IX1` (`Some_Code1`),
KEY `sometable_IX2` (`Some_Code2`),
FOREIGN KEY (`Some_Code1`) REFERENCES `some_parent_table` (`Some_Code1`)
) TYPE=InnoDB;


Sorry if this isn't too great of an example but it should be enough to get you started.

Reply With Quote
  #3  
Old March 5th, 2003, 02:27 AM
danjel danjel is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 7 danjel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
also you need MySQL Server 3.23.44 or better..

Reply With Quote
  #4  
Old March 5th, 2003, 10:21 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
ctownsen357:

thanks... i read an example like that on mysql.net, but it didn't make sense to me...

someone actually explained to me that you do'nt have to necessarily set up constraints in MySQL. I've had a lot of practice with Oracle, and thus I was used to the way things operate there...

I'll read up on the other table-type (InnuDB or whatever?) and perhaps it's more along the lines of what I need.

For now i've set up my tables like this:

CREATE TABLE one
(one_id INT NOT NULL PRIMARY KEY,
desc VARCHAR);

CREATE TABLE two
(two_id INT NOT NULL PRIMARY KEY,
desc VARCHAR,
one_id INT);


then when i use it i would just join them in the SELECT statement... i was expecting a way to restrict constraints with normal tables... guess i'll read about that new kind...

thanks again!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > MySQL > Linking tables?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway