views:

59

answers:

2

I created this using MySQL WorkBench

CREATE  TABLE IF NOT EXISTS `bakasura_new`.`cities` (
  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(255) NOT NULL COMMENT 'City Name' ,
  `short_name` VARCHAR(255) NOT NULL COMMENT 'Short Name' ,
  `country_id` INT(11) UNSIGNED NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_cities_countries` (`country_id` ASC) ,
ENGINE = InnoDB;

I am getting this error

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that

corresponds to your MySQL server version for the right syntax to use near '= InnoDB' at line 8

+3  A: 

You have a dangling comma here:

INDEX `fk_cities_countries` (`country_id` ASC) ,

And you also have a missing parenthesis at the end:

CREATE  TABLE IF NOT EXISTS `bakasura_new`.`cities` (
  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(255) NOT NULL COMMENT 'City Name' ,
  `short_name` VARCHAR(255) NOT NULL COMMENT 'Short Name' ,
  `country_id` INT(11) UNSIGNED NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_cities_countries` (`country_id` ASC)
) ENGINE = InnoDB;
Daniel Vassallo
i tried that before.. doesnt work :(
Harsha M V
@Harsha M V: Just tried it myself, and it worked. Note that I removed a comma and added a closing parenthesis.
Daniel Vassallo
ouch.. sorry didnt notice that :D thanks a lot it worked :D
Harsha M V
+1  A: 

There is a ) missing at the end of the last )

INDEX `fk_cities_countries` (`country_id` ASC) )
DrColossos
thank you. works now :D Mysql Workbench had created Constraints which i wanted to remove. guess i deleted the bracket bymistake. any idea how to export from mysql Workbench with out constraints
Harsha M V
@Harsha: What type of constraints did Workbench create? Can you give an example?
Daniel Vassallo
CREATE TABLE IF NOT EXISTS `areas` ( `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT , `name` VARCHAR(255) NOT NULL , `slug` VARCHAR(255) NULL , `zipcode` INT(11) NULL , `latitude` VARCHAR(255) NULL , `longitude` VARCHAR(255) NULL , `city_id` INT(11) UNSIGNED NOT NULL , PRIMARY KEY (`id`) , CONSTRAINT `fk_areas_cities1` FOREIGN KEY (`city_id` ) REFERENCES `cities` (`id` ) ON DELETE NO ACTION ON UPDATE NO ACTION)ENGINE = InnoDB;CREATE INDEX `fk_areas_cities1` ON `areas` (`city_id` ASC) ;
Harsha M V
@Harsha: It looks like you want to remove the foreign key on `city_id`. I think you can remove the foreign key from the EER diagram: http://dev.mysql.com/doc/workbench/en/wb-relationship-tools.html. Just delete the link. By removing that constraint manually, you were effectively removing the constraint on the link.
Daniel Vassallo
but i want the linking between the two tables. otherwise i am not able to link them right ?
Harsha M V
@Harsha: You will still be able to "link" the tables in your queries using JOINs, even if there is no foreign key constraint. Try it out.
Daniel Vassallo
@Daniel guess it only helps the EER diagram :D
Harsha M V