3

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

2 Answers 2

6

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;
Sign up to request clarification or add additional context in comments.

1 Comment

@Harsha M V: Just tried it myself, and it worked. Note that I removed a comma and added a closing parenthesis.
1

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

INDEX `fk_cities_countries` (`country_id` ASC) )

7 Comments

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: What type of constraints did Workbench create? Can you give an example?
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: 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: 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.
but i want the linking between the two tables. otherwise i am not able to link them right ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.