ERROR 1064 (42000): SQL syntax error - mysql

MYSQL command
I'm using command prompt
create table user
<id int<11> unsigned auto_increment primary key not null,
username jack<25> not null,
passwd jack<25> not null,
email jack<40> not null>;
the 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'table user' at line 1
How to fix this ?

First off, you appear to be using angle brackets rather than parentheses. Second, I'm not sure what jack is supposed to be but it's not standard SQL.
I'd be starting with this instead (though you could also use varchar instead of char):
create table user (
id int(11) unsigned auto_increment primary key not null,
username char(25) not null,
passwd char(25) not null,
email char(40) not null
);

Use parentheses instead of angle brackets
Use Valid DataType
Try this
create table user(id int(11) unsigned auto_increment primary key not null,
username varchar(25) not null,
passwd varchar(25) not null,
email varchar(40) not null);

First : use () instead of <>
Second : use varchar instead of jack, jack is incorrect datatype
so query should be :
create table user ( /* <-- note the brackets */
id int(11) unsigned auto_increment primary key not null,
username varchar(25) not null, /*incorrect data type "jack"*/
passwd varchar(25) not null, /*use varchar instead of jack */
email varchar(40) not null
);

Related

How do I debug SQL query with the following error message

This is my query.
CREATE TABLE `requirements`
(
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`requirement_id` VARCHAR NOT NULL,
`state` VARCHAR NOT NULL,
`city` VARCHAR NOT NULL,
`salary_per_anum` FLOAT NOT NULL,
`is_closed` TINYINT(1) NOT NULL,
`created_updated` DATETIME NOT NULL,
CONSTRAINT `pk_requirements` PRIMARY KEY(`id`)
);
and this is the 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 'NOT NULL, `state` VARCHAR NOT NULL, `city` VARCHAR NOT NULL, `salary_per_anum` F' at line 1
how can I debug what seems to be the issue?
You need to define a length of the string colum like
`requirement_id` VARCHAR(100)
and the same with column state and city.
But since requirement_id looks like a number id column it must be of the same type as id in table requirements, probably int.
Also your constraint seems to be defined wrong. It should refer to the table requirements.

importing a statement into mysql

I can't find and error, when I try to execute:
create database android_api
use android_api
create table users(
id int(11) primary key auto_increment,
unique_id varchar(23) not null unique,
name varchar(50) not null,
email varchar(100) not null unique,
encrypted_password varchar(80) not null,
salt varchar(10) not null,
created_at datetime,
updated_at datetime null
);
I get and error " #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 '
use android_api
create table users(
id int(11) primary key auto_increme' at line 3"
just separate your code with ';'
create database android_api;
use android_api;
create table users(
id int(11) primary key auto_increment,
unique_id varchar(23) not null unique,
name varchar(50) not null,
email varchar(100) not null unique,
encrypted_password varchar(80) not null,
salt varchar(10) not null,
created_at datetime,
updated_at datetime null
);
The answer is that you can't do it.
Do those processes in 3 different queries.

Mysql creating table error integer

With this code:
create table jogadores(
id INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
nome varchar NOT NULL,
idade int NOT NULL UNSIGNED,
nacionalidade varchar NOT NULL
)
I keep getting this error:
)
Error report -
SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOT NULL,
idade int NOT NULL UNSIGNED,
nacionalidade varchar NOT NULL
)' at line 3.
Also, I get the red underline under the "T" and the "(" in "INT(10)".
varchar() should have a length:
create table jogadores (
id INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
nome varchar(255) NOT NULL,
idade int UNSIGNED NOT NULL,
nacionalidade varchar(255) NOT NULL
);
And UNSIGNED needs to go immediately after the numeric declaration, not after NOT NULL. See here.
You need to specify the length of the varchar i.e. varchar(100).

Syntax error creating MySQL table

Perhaps I'm just too used to Postgres but why am I getting this error
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 '{ id int not null AUTO_INCREMENT, email varchar(100) not null,
primary key(id' at line 1
when I run this?
create table `users`{
id int not null AUTO_INCREMENT,
email varchar(100) not null,
primary key(id)
};
Use parenthesis (normal brackets) () not braces:
create table `users` (
id int not null AUTO_INCREMENT,
email varchar(100) not null,
primary key(id)
);
the correct syntax is :
CREATE TABLE users (
id INT NOT NULL AUTO_INCREMENT,
email VARCHAR(100) NOT NULL,
PRIMARY KEY(id)
);
check it out here for your version:
https://dev.mysql.com/doc/refman/4.1/en/creating-tables.html

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

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
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.
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
Use varchar instead of VAR_CHAR and omit the comma in the last line i.e.phone INT NOT NULL
);. The last line during creating table is kept "comma free".
Ex:- CREATE TABLE COMPUTER
(
Model varchar(50)
);
Here, since we have only one column ,that's why there is no comma used during entire code.