Pergunta

Using mySQLAdmin tool, I try to create a table. The tool generates the SQL statement, and then replorts a "Can't create table" with no other clue on what error it is!

Here it is :

CREATE TABLE `C121535_vubridge`.`Products` (
  `pr_ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  `pr_Name` VARCHAR(45) NOT NULL,
  `pr_Type` VARCHAR(2) NOT NULL COMMENT 'H=Hand Series V=VuBridge software E=Event Subs S=Sponsoring',
  `pr_AuthorID` INTEGER UNSIGNED COMMENT '= m_ID (for Bridge Hand Series',
  `pr_SponsorID` INTEGER UNSIGNED NOT NULL,
  `pr_DateCreation` DATETIME NOT NULL,
  `pr_Price` FLOAT NOT NULL,
  `pr_DescriptionText` TEXT,
  `pr_Description` VARCHAR(245),
  PRIMARY KEY (`pr_ID`),
  CONSTRAINT `FK_prAuthor` FOREIGN KEY `FK_prAuthor` (`pr_AuthorID`)
    REFERENCES `Members` (`m_ID`)
    ON DELETE SET NULL
    ON UPDATE NO ACTION,
  CONSTRAINT `FK_Sponsor` FOREIGN KEY `FK_Sponsor` (`pr_SponsorID`)
    REFERENCES `Members` (`m_ID`)
    ON DELETE SET NULL
    ON UPDATE NO ACTION
) ENGINE = InnoDB;

Can someone help?

Foi útil?

Solução

The CREATE TABLE works for me if I omit the foreign key references:

CREATE TABLE `Products` (
 `pr_ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
 `pr_Name` VARCHAR(45) NOT NULL,
 `pr_Type` VARCHAR(2) NOT NULL COMMENT 'H=Hand Series V=VuBridge software E=Event Subs S=Sponsoring',
 `pr_AuthorID` INTEGER UNSIGNED COMMENT '= m_ID (for Bridge Hand Series',
 `pr_SponsorID` INTEGER UNSIGNED NOT NULL,
 `pr_DateCreation` DATETIME NOT NULL,
 `pr_Price` FLOAT NOT NULL,
 `pr_DescriptionText` TEXT,
 `pr_Description` VARCHAR(245),
 PRIMARY KEY (`pr_ID`)
)

...so I'm inclined to believe that C121535_vubridge.MEMBERS does not already exist. C121535_vubridge.MEMBERS needs to be created before the CREATE TABLE statement for the PRODUCTS table is run.

Outras dicas

Just split up the create table and try one part at the time. This way you should be able to identify a single line that it fails on.

I do note in the reference manual that if a symbol subclause is given for the CONSTRAINT clause (in your case, the back-quoted strings before FOREIGN KEY in each clause, FK_prAuthor and FK_Sponsor) have to be unique over the database. Are they? If not, that symbol can be omitted and InnoDB will assign then automatically.

Similarly, the tables your FKs refer to may not have the structure that this create statement expects.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top