Michael Satterwhite <[EMAIL PROTECTED]> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Monday 21 July 2003 04:14, Egor Egorov wrote: >> Michael Satterwhite <[EMAIL PROTECTED]> wrote: >> > I'm trying to add a foreign key to a table. All tables are INNODB. Table >> > a has following partial Definition: >> > >> > TableA >> > ( Fld1 int Primary Key,... >> > ) >> > >> > TableB >> > (Fld2 int Primary Key, >> > Fld1 int not null, ... >> > ) >> > >> > I use the following Statement: >> > >> > Alter Table TableB Add Constraint FK1 (Fld1) References TableA >> > (Fld1) on delete cascade; >> > > <SNIP> > > Sorry, I tried to generalize the tables, then put the error verbatim - my > fault. With the table definitions as above, and the ALTER TABLE statement > exactly as above, I get the following error: > > ERROR 1064: You have an error in your SQL syntax. Check the manual that > corresponds to your MySQL server version for the right syntax to use near > '(Fld1) References TableA (Fld1) on Delete Cascade' at line 1
Syntax of the above ALTER TABLE statement is wrong. Correct syntax is: ALTER TABLE yourtablename ADD [CONSTRAINT symbol] FOREIGN KEY (...) REFERENCES anothertablename(...) [on_delete_and_on_update_actions] http://www.mysql.com/doc/en/InnoDB_foreign_key_constraints.html -- For technical support contracts, goto https://order.mysql.com/?ref=ensita This email is sponsored by Ensita.net http://www.ensita.net/ __ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / Egor Egorov / /|_/ / // /\ \/ /_/ / /__ [EMAIL PROTECTED] /_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.net <___/ www.mysql.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]