tags:

views:

35

answers:

1

I have a script in MySQL that creates two tables, the second table references a field in the first table, now when I try to run this script in one batch it returns an error. My guess is that it checks the referenced table in the second table definition before creating the tables.

Any idea how I can create both tables at once?

Thanks

Edit:

Example:

CREATE TABLE table1
(
    ID INT NOT NULL,
    PRIMARY KEY (ID)
) ENGINE=InnoDB;

CREATE TABLE table2
(
    ID INT NOT NULL,
    FID INT NOT NULL ,
    PRIMARY KEY (ID),
    FOREIGN KEY (FID) REFERENCES table1 (ID)
) ENGINE=InnoDB;

If I create the first table, then create the second table everything works fine, but when I run this in one batch it returns an error

+2  A: 

the simple thing , to create first the 2 tables, after that do alter table and add the reference.

Haim Evgi
Thanks for the suggestion, this will make my script look ugly but it seems like the only way
Waleed Eissa
quick and dirty :)
Haim Evgi
lol ............................
Waleed Eissa