MySQL 5.6.13 not executing create table properly - mysql

I have the following SQL to create a table on a MySQL 5.6.13 instance:
CREATE TABLE 'exchange' (
'id' int NOT NULL AUTO_INCREMENT,
'abbrev' varchar(32) NOT NULL,
'name' varchar(255) NOT NULL,
'city' varchar(255) NULL,
'country' varchar(255) NULL,
'currency' varchar(128) NULL,
'time_zone_offset' time NULL,
'created_date' datetime NOT NULL,
'last_updated_date' datetime NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
However, I keep getting the following unhelpful 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
''exchange' ( 'id' int NOT NULL AUTO_INCREMENT,
'abbrev' varchar(32) NOT NULL, 'n' at line 1
I must be missing something glaringly obvious...
Any ideas where I'm going wrong?

Try :
CREATE TABLE exchange (
Ref:
http://dev.mysql.com/doc/refman/5.1/en/create-table.html

Remove all quotes, this helped me on a windows machine command line

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.

Error 1064, my SQL command

I am really new to this so don't laugh .
I am trying to input a command in MySQL but I keep getting this syntax error.
It is prolly stupid, but I have little to no knowledge in sql.
CREATE TABLE `serial`.`serial`(
`id` INT NOT NULL AUTO_INCREMENT,
`serial` VARCHAR NOT NULL,
`hwid` VARCHAR NOT NULL,
PRIMARY KEY(`id`)
)
It keeps giving me :
**
#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 'NOT NULL,
`hwid` VARCHAR NOT NULL,
PRIMARY KEY(`id`)
)' at line 3
If someone could help me, it would be really appreciated. :)
varchar needs to be declared with a length:
CREATE TABLE `serial`.`serial` (
`id` INT NOT NULL AUTO_INCREMENT,
`serial` VARCHAR(255) NOT NULL,
`hwid` VARCHAR(255) NOT NULL,
PRIMARY KEY(`id`)
);
Here is a little SQL Fiddle showing it.

I keep getting an error when trying to make a table in phpmyadmin

when I was trying to run this code:
USE user;
CREATE TABLE IF NOT EXISTS 'posts' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'body' text NOT NULL,
'date_added' date NOT NULL,
'added_by' varchar(255) NOT NULL,
'user_posted_to' varchar(255) NOT NULL,
PRIMARY KEY ('id')
)ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;
It gave me this 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 ''posts' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'body' text NOT NULL,
'dat' at line 1
how do I solve it? By the way, I already selected a database? Any help would be appreciated.
Get rid of all the "'" marks.
CREATE TABLE IF NOT EXISTS posts (
id int(11) NOT NULL AUTO_INCREMENT,
body text NOT NULL,
date_added date NOT NULL,
added_by varchar(255) NOT NULL,
user_posted_to varchar(255) NOT NULL,
PRIMARY KEY (id)
)ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;
Here is a fiddle with a working creation.

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.

Why is my Update statement not working?

Using the following query, I can't figure out why my update is not working. I'm sure its something stupid, but any help is greatly appreciated:
UPDATE Mail
SET From="Spouse"
WHERE ItemNum=9;
The Error is:
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 'From="Spouse" WHERE ItemNum=9' at line 1
The schema of Mail is:
CREATE TABLE `Mail` (
`ItemNum` int(11) NOT NULL auto_increment,
`Qtr` int(11) NOT NULL default '0',
`MsgDate` date default NULL,
`From` varchar(64) default NULL,
`Message` varchar(255) default NULL,
PRIMARY KEY (`ItemNum`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=latin1
From is a MySQL reserved keyword. Surround it with backticks:
UPDATE Mail
SET `From`="Spouse"
WHERE ItemNum=9;