ERROR 1064 (42000): you have an error in the SQL syntax;

I have 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 message:

 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 
+4
source share
2 answers

This is varchar , 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 the SQL tool to visualize valid errors such as MySQL Workbench.

+9
source

Try the following:

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 
+2
source

Source: https://habr.com/ru/post/1501660/


All Articles