Skip navigation links

MySQL Forums :: PHP :: foreign key, alter tables


Advanced Search

foreign key, alter tables
Posted by: Andy Deans ()
Date: November 03, 2009 06:41PM

hi,

i have played around a bit and created a few tables in my database.

tables are:

table1 id pk, username, password, email
table2 firstname, lastname, assignedto

i was hoping to setup a foreign key relationship so that in my webpage i could set assigned to from table2 to the username in table1 with a drop down listing the users so i can assign it and insert the record. my web host does not allow phpmyadmin relation view therefore after a previous post i cannot create the foreign jey that way, what i have found is this:

ALTER TABLE tbl_name
ADD [CONSTRAINT [symbol]] FOREIGN KEY
[index_name] (index_col_name, ...)
REFERENCES tbl_name (index_col_name,...)
[ON DELETE reference_option]
[ON UPDATE reference_option]

however not sure if this would work as tables are setup already? and is it best to setup foreign key to do this or joins or have it all in one table but from the books i have read it says to avoid doing that.

any help would be great.

many thanks to you all,

andy

Options: ReplyQuote


Subject Written By Posted
foreign key, alter tables Andy Deans 11/03/2009 06:41PM


Sorry, only registered users may post in this forum.