Ask a Question related to MySQL, Design and Development.
-
Bruno Guerpillon #1
Foreign key
Hi
First, i assume i RTFM but am new to MySQL world so i got some problems.
I got 2 tables
TABLE1
T1Col1 Varchar(30) PRIMARY KEY
TABLE2
T2col1
T2col2
What i'd like to do is to set the T2col2 as foreign key for the T1Col1.
Any1 got the synthaxe to do it ?
Regards
Bruno
Bruno Guerpillon Guest
-
Self Referencing foreign key
I am trying to create an employee/supervisor relationship. Since both are essentially employees, I created a foreign key relationship which... -
Find out if a key is foreign or not?
I'm trying to find out if a key in the database is a foreign key and what it is linked to. This way I could automate lookups instead of coding them... -
Foreign char - ASP to DB
Hi, I have a problem on storing foreign char to SQL DB. If user inputs a foreign char from asp page, for example, "ROSÉ", it will be stored in... -
foreign key is blank
I have two forms in a one-to-many relationship. I've also created a data entry form for the two of them using a main form and a subform. The... -
SQL DMO + Foreign Keys
I have table1 that has a Foriegn Key to table2, using the sql dmo i am able to get the script from Table1 to create the Foreign key with Table2 no... -
Giuseppe Maxia #2
Re: Foreign key
Bruno Guerpillon wrote:
To use foreign keys, you have to:> Hi
>
> First, i assume i RTFM but am new to MySQL world so i got some problems.
> I got 2 tables
>
> TABLE1
> T1Col1 Varchar(30) PRIMARY KEY
>
> TABLE2
> T2col1
> T2col2
>
>
>
> What i'd like to do is to set the T2col2 as foreign key for the T1Col1.
> Any1 got the synthaxe to do it ?
>
> Regards
> Bruno
>
>
- use InnoDB tables;
- have a primary key in the parent table
- have a key for the foreign key candidate column in the child table
- use the constraint syntax:
CONSTRAINT `constraint_name` FOREIGN KEY `key_name` (T2col2) references TABLE1 (T1Col1)
This is the RTFM part :)
[url]http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html[/url]
[url]http://dev.mysql.com/doc/refman/5.0/en/example-foreign-keys.html[/url]
[url]http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-foreign-keys.html[/url]
ciao
gmax
--
_ _ _ _
(_|| | |(_|>< The Data Charmer
_|
[url]http://datacharmer.blogspot.com/[/url]
Giuseppe Maxia Guest
-
Jim Michaels #3
Re: Foreign key
If you've installed MySQL locally, it comes with a pretty decent manual,
especially if it's on Windows. you just go into the index tab and type in
alter table. you can also learn about alter table by looking at the SQL
generated when you modify a table in the query browser.
I think the syntax would look something like
ALTER TABLE TABLE2 ADD FOREIGN KEY ix_t2t2col2t1col1 (T2col2) REFERENCES
TABLE1(T1Col1);
"Bruno Guerpillon" <toto@toto.fr> wrote in message
news:43d60d41$0$375$636a55ce@news.free.fr...> Hi
>
> First, i assume i RTFM but am new to MySQL world so i got some problems.
> I got 2 tables
>
> TABLE1
> T1Col1 Varchar(30) PRIMARY KEY
>
> TABLE2
> T2col1
> T2col2
>
>
>
> What i'd like to do is to set the T2col2 as foreign key for the T1Col1.
> Any1 got the synthaxe to do it ?
>
> Regards
> Bruno
>
Jim Michaels Guest



Reply With Quote

