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;
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.
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.
The syntax error appears to be the empty parenthesis at:
INDEX vAuthorID ()
,FOREIGN KEY ()
andREFERENCES proquotes.author_info ()
. Those parenthesis should reference one or more table attributes.For example:
The last parenthesis for the
REFERENCES
clause should reference an attribute inauthor_info
, and not fromthquotes
. Therefore you may need to changevAuthorID
accordingly.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.