List:General Discussion« Previous MessageNext Message »
From:David Blomstrom Date:May 13 2004 1:11am
Subject:From the top! (primary/foreign keys)
View as plain text  
OK, I've made some changes, and I'm still trying to
figure out this foreign key stuff. This time, I'll
focus on just two tables, named "continents" and
"nations."

I put screen shots of their structure and some sample
rows online at http://www.geoworld.org/try.gif

It sounds like non-repeating numerals are generally
preferred for use as primary keys, but letters can be
used. I'd greatly prefer to use letters, because it's
much more easier for me to match them with their
respective countries and continents when working on
related tables.

But if this experiment fizzles out, too, I may abandon
abbreviations and just use numerals for my primary
keys.

At any rate, I want to join the continents and nations
tables via a shared column named "CCode." In the
continents table, it's designated a foreign key, and
none of the codes repeat. In the nations table, some
of the values do repeat - obviously, Canada and the
U.S. both merit the abbreviation na (North America).

If I understand correctly, I have to designate a
column a unique index BEFORE I can make it a foreign
key. I tried designating the CCode field on the table
"nations" a unique index, without success. Is that
because of the repeating values? I then tried to
designate a column with non-repeating numerals a
unique index, but that didn't work, either.

I finally learned how to create a foreign key with
phpMyAdmin, but that doesn't work, either. I put
screenshots of my trials online at
http://www.geoworld.org/fk.gif

(The second table was then named nations2, but I've
since renamed it to nations.)

If the only solution is to make all my primary keys
non-repeating numerals, then I'll go that route. If
there are other problems, then I'd like to know if
anyone on this list knows how to designate foreign
keys with either MySQL-Front or SQLyog. I've used them
as workarounds for other problems I have with
phpMyAdmin, but their Help sections are worthless for
foreign keys.

Thanks.


	
		
__________________________________
Do you Yahoo!?
Yahoo! Movies - Buy advance tickets for 'Shrek 2'
http://movies.yahoo.com/showtimes/movie?mid=1808405861 
Thread
From the top! (primary/foreign keys)David Blomstrom13 May
  • Re: From the top! (primary/foreign keys)Ligaya Turmelle13 May
    • Re: From the top! (primary/foreign keys)David Blomstrom13 May
    • Re: From the top! (primary/foreign keys)David Blomstrom13 May