5 Replies - 211 Views - Last Post: 10 August 2017 - 07:56 AM

#1 roparzhhemon  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 19
  • Joined: 06-December 15

What's the syntax error in this MySQL command ?

Posted 10 August 2017 - 07:09 AM

What's the syntax error in this MySQL command ?


I have a substitles.sql file whose contents is this :

CREATE TABLE `javaee`.`draft` ( 
    `index` INT NOT NULL AUTO_INCREMENT , 
	`timeInterval` VARCHAR NOT NULL ,
	`originalText` VARCHAR NOT NULL , 
	`translatedText` VARCHAR NOT NULL ) 
ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;



But when I try source subtitles.mysql in my console, I get the following error message :

ERROR 1064 (42000) at line 1 in file: '(...)/subtitles.sql': You have an error in your SQL syntax; 
 the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL ,
	`originalText` VARCHAR NOT NULL , 
	`translatedText` VARCHAR NOT NUL' at line 3



Is This A Good Question/Topic? 0
  • +

Replies To: What's the syntax error in this MySQL command ?

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4136
  • View blog
  • Posts: 13,056
  • Joined: 08-June 10

Re: What's the syntax error in this MySQL command ?

Posted 10 August 2017 - 07:13 AM

VARCHAR requires a length.
Was This Post Helpful? 1
  • +
  • -

#3 roparzhhemon  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 19
  • Joined: 06-December 15

Re: What's the syntax error in this MySQL command ?

Posted 10 August 2017 - 07:30 AM

View PostDormilich, on 10 August 2017 - 07:13 AM, said:

VARCHAR requires a length.


Thank you, that helped, I changed my code to
CREATE TABLE `javaee`.`draft` ( 
    `index` INT NOT NULL AUTO_INCREMENT , 
	`timeInterval` VARCHAR(29) NOT NULL ,
	`originalText` VARCHAR(100) NOT NULL , 
	`translatedText` VARCHAR(100) NOT NULL ) 
ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;



Now I get another error :
ERROR 1075 (42000) at line 2 in file: '/Users/ewandelanoy/Documents/Web_Projects/workspace/SubtitleTranslator/WebContent/WEB-INF/subtitles.sql': Incorrect table definition; there can be only one auto column and it must be defined as a key


Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4136
  • View blog
  • Posts: 13,056
  • Joined: 08-June 10

Re: What's the syntax error in this MySQL command ?

Posted 10 August 2017 - 07:36 AM

The AUTO_INCREMENT'ed column must be (part of) the primary key for the table.
Was This Post Helpful? 1
  • +
  • -

#5 roparzhhemon  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 19
  • Joined: 06-December 15

Re: What's the syntax error in this MySQL command ?

Posted 10 August 2017 - 07:55 AM

Thank you again, I finally found something that works :

CREATE TABLE `javaee`.`draft` ( 
    `index` INT NOT NULL AUTO_INCREMENT , 
	`timeInterval` VARCHAR(29) NOT NULL ,
	`originalText` VARCHAR(100) NOT NULL , 
	`translatedText` VARCHAR(100) NOT NULL,
	PRIMARY KEY (`index`) ) 
ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;


Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4136
  • View blog
  • Posts: 13,056
  • Joined: 08-June 10

Re: What's the syntax error in this MySQL command ?

Posted 10 August 2017 - 07:56 AM

Be aware though that MyISAM does not support Foreign Keys.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1