views:

47

answers:

3

while executing the following query, i get an error that there's an error in the syntax near line 9. since i'm using mysql workbench, i can't really figure out what could be wrong:

CREATE  TABLE IF NOT EXISTS `proquotes`.`thquotes` (

  `idQuotes` INT NOT NULL AUTO_INCREMENT ,

  `vAuthorID` VARCHAR(8) CHARACTER SET 'utf8' NOT NULL ,

  `vAuthor` VARCHAR(45) CHARACTER SET 'utf8' NOT NULL ,

  `cQuotes` MEDIUMTEXT CHARACTER SET 'utf8' NOT NULL ,

  `cArabic` MEDIUMTEXT CHARACTER SET 'utf8' NOT NULL ,

  `vReference` VARCHAR(100) CHARACTER SET 'utf8' NOT NULL ,

  PRIMARY KEY (`idQuotes`) ,

  INDEX `vAuthorID` () ,

  CONSTRAINT `vAuthorID`

    FOREIGN KEY ()

    REFERENCES `proquotes`.`author_info` ()

    ON DELETE NO ACTION

    ON UPDATE NO ACTION)

DEFAULT CHARACTER SET = utf8;

table author_info:

CREATE  TABLE IF NOT EXISTS `proquotes`.`author_info` (  

`vAuthorID` INT NOT NULL ,  `vAuthor` VARCHAR(45) CHARACTER 

SET 'utf8' NOT NULL ,  `nQuotes` INT NOT NULL ,  PRIMARY KEY 

(`vAuthorID`) ,  UNIQUE INDEX `vAuthorID_UNIQUE` (`vAuthorID` 

ASC) )DEFAULT CHARACTER SET = utf8;
+1  A: 

The syntax error appears to be the empty parenthesis at: INDEX vAuthorID (), FOREIGN KEY () and REFERENCES proquotes.author_info (). Those parenthesis should reference one or more table attributes.

For example:

INDEX `vAuthorID` (`vAuthorID`) ,
CONSTRAINT `vAuthorID`
   FOREIGN KEY (`vAuthorID`)
   REFERENCES `proquotes`.`author_info` (`vAuthorID`)

The last parenthesis for the REFERENCES clause should reference an attribute in author_info, and not from thquotes. Therefore you may need to change vAuthorID accordingly.

Daniel Vassallo
i did that. now it says: `ERROR 1005: Can't create table 'proquotes.thquotes' (errno: 150)`
fuz3d
@fusion: What MySQL version are you using? You may need to create an index manually on `author_info.vAuthorID`. Source: http://forums.mysql.com/read.php?22,19755,19755#msg-19755
Daniel Vassallo
@fusion: ... Or else, it might that `author_info.vAuthorID` is not the exact same data type as `thquotes.vAuthorID`. Source: http://www.devdaily.com/blog/post/mysql/mysql-error-1005-hy000
Daniel Vassallo
i'm using mysql workbench 5.2.17 Beta and mysql 5.1
fuz3d
i've updated the question with the sql query of author_info. please take a look at it.
fuz3d
@fusion: OK, it looks like `vAuthorID` in the new table `thquotes` is a `VARCHAR(8)`, but in the `author_info` table it is an `INT`. They have to be the same data type. One of them needs to change. If you want to change the `thquotes` table, try replacing `vAuthorID VARCHAR(8) CHARACTER SET 'utf8' NOT NULL ,` with `vAuthorID INT NOT NULL ,`
Daniel Vassallo
thanks for the reply. the datatype was different.
fuz3d
+1  A: 

It looks like you need a column name in the parentheses after the INDEX keyword?

See http://dev.mysql.com/doc/refman/5.5/en/create-table.html.

SamB
A: 

The three obvious errors are a lack of fields in your INDEX and FOREIGN KEY definitions. You have to specify one or more fields for each, otherwise it's a syntax error.

INDEX `vAuthorID` () ,  <--need a field here in the ()'s
CONSTRAINT `vAuthorID`
    FOREIGN KEY ()  <---another field here in the ()'s
    REFERENCES `proquotes`.`author_info` ()  <--and yet another field here in the ()'s

You're also not specifying which database engine to use, which generally means MySQL will use MyISAM, so all of your foreign key specifications will be silently dropped.

Marc B