Batch problem in MySQL?

I have a script in MySQL that creates two tables, the second table refers to a field in the first table, now when I try to run this script in one batch, it returns an error. I am assuming 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 it in one batch it returns an error

Update: It looks like this issue has been fixed with MySQL 5.5. It now works correctly in one batch, even if you have foreign key constraints in some of your table definitions.

0


a source to share


1 answer


simple thing is to create 2 tables first, after that change the table and add a link.



+3


a source







All Articles