Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR 1064 (42000): You have an error in your SQL syntax;

Tags:

sql

mysql

I have a MySQL commands:

CREATE DATABASE IF NOT EXISTS courses;

USE courses

CREATE TABLE IF NOT EXISTS teachers(
    id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
    name VAR_CHAR(50) NOT NULL,
    addr VAR_CHAR(255) NOT NULL,
    phone INT NOT NULL,
);

When I run it, I get an error:

ERROR 1064 (42000): 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 'VAR_CHAR(50) NOT NULL, addr VAR_CHAR(255) NOT
NULL, phone INT NOT NULL, )' at line 3
like image 812
SkyStar Avatar asked Sep 11 '13 13:09

SkyStar


People also ask

What is the error in MySQL syntax?

The 1064 error displays any time you have an issue with your SQL syntax, and is often due to using reserved words, missing data in the database, or mistyped/obsolete commands.

What does error 1064 mean in MySQL?

Error #1064 means that MySQL can't understand your command. To fix it: Read the error message. It tells you exactly where in your command MySQL got confused.


2 Answers

It is varchar and not var_char

CREATE DATABASE IF NOT EXISTS courses;

USE courses;

CREATE TABLE IF NOT EXISTS teachers(
    id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
    name VARCHAR(50) NOT NULL,
    addr VARCHAR(255) NOT NULL,
    phone INT NOT NULL
);

You should use a SQL tool to visualize possbile errors like MySQL Workbench.

like image 96
juergen d Avatar answered Nov 14 '22 21:11

juergen d


Try this:

Use back-ticks for NAME

CREATE TABLE `teachers` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `addr` varchar(255) NOT NULL,
  `phone` int(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
like image 39
Sathish D Avatar answered Nov 14 '22 23:11

Sathish D