MySQL error 1064 for 3rd table in file - mysql

I am having a very strange issue with creating a table in mySQL. Every time I run the file I get this error:
"ERROR 1064 (42000) at line 36 in file: 'QStoreDB.sql': 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 ')' at line 8"
For this section of code:
CREATE TABLE customers
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(45) NOT NULL,
address1 VARCHAR(160) NOT NULL,
address2 VARCHAR(160) NOT NULL,
cart INT,
);
This is the third table in my file. The other 2 are created with no issue using the same format. I have tried removing all comments, as you can see I have removed all of my constraints but even when I input the data in its most basic form (ie whats writen above this paragraph) it still doesn't run. I have also tried putting my field names in `` to no avail.
I am at a complete loss and scouring the internet has not helped me so I'm hoping some one here has experienced this as can point me in the right direction.

Whilst defining PRIMARY KEY you do not have to write INT NOT NULL
CREATE TABLE customers
(
id PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(45) NOT NULL,
address1 VARCHAR(160) NOT NULL,
address2 VARCHAR(160) NOT NULL,
cart INT
);
And there shouldn't be a comma at the end.

Related

Receiving error in an attempt to define my table [duplicate]

This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 3 years ago.
I'm working on a group project and I'm trying to drop my database, but I'm receiving the same error, no matter how I try to manipulate what I wrote. Hopefully someone can help me understand where I went wrong.
For the
type VARCHAR NOT NULL,
description VARCHAR,
image VARCHAR,
I've tried adding in "DEFAULT NULL" and adding in numbers next to VARCHAR. I keep getting the same error message. I left it as what I put above because with my API, I don't want to restrict the amount of characters I'll be receiving when I call on it.
CREATE DATABASE recycleThis_db;
USE recycleThis_db;
CREATE TABLE materials (
id INT(11) NOT NULL AUTO_INCREMENT,
type VARCHAR NOT NULL,
description VARCHAR,
image VARCHAR,
materialID INT(11) NOT NULL,
PRIMARY KEY (id)
);
I keep getting this 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,
description VARCHAR,
image VARCHAR,
materialID INT NOT NULL' at line 3
I believe VARCHAR requires a length specifier e.g. VARCHAR(10) or VARCHAR(250)
CREATE TABLE `materials`
( `id` INT(11) NOT NULL AUTO_INCREMENT
, `type` VARCHAR(80) NOT NULL
, `description` VARCHAR(255)
, ...
Reference: https://dev.mysql.com/doc/refman/8.0/en/char.html
excerpt:
The CHAR and VARCHAR types are declared with a length that indicates the maximum number of characters you want to store. For example, CHAR(30) can hold up to 30 characters.

ERROR 1064 (42000), when creating a mysql table

I am trying to create a table, but it gives me this 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 touse near ' INT NOT NULL AUTO_INCREMENT
Here is my code:
CREATE TABLE bowling_scores (
PlayerID, INT NOT NULL AUTO_INCREMENT
, LName VARCHAR(100) NOT NULL
, FName VARCHAR(100) NOT NULL
, Game1 INT NULL
, Game2 INT NULL
, Game3 INT NULL
, Game4 INT NULL
, PRIMARY KEY (PlayerID)
);
Here's a tip about syntax error messages: the message tells you where the error is.
check the manual that corresponds to your MySQL server version for the right syntax to use near ' INT NOT NULL AUTO_INCREMENT
This is telling you that MySQL became confused because it wasn't expecting to see that text. This usually means you made a mistake at that point, or immediately before it.
This can help you narrow down your search in the SQL statement to the point where it went wrong.
The error message also tells you what to do: check the manual. You should help yourself become better at SQL by reading documentation and examples.
I've been using MySQL for nearly 20 years, but I still refer to the reference docs every day. In fact, it's because I am experienced with MySQL that I know this is the right thing to do.
All SQL statements have a reference page in the manual. Here's the page for CREATE TABLE: https://dev.mysql.com/doc/refman/5.7/en/create-table.html
The MySQL manual is large, so it's easy to think "I don't know where the right page is." Gradually you can learn how the manual is organized. Pay attention to the hierarchy of links on the left column. When in doubt, just use Google for phrases like "mysql create table syntax".
You should be able to answer simple syntax errors for yourself instead of posting to Stack Overflow. You'll get your answer more quickly!
This is an obvious error:
PlayerID, INT NOT NULL AUTO_INCREMENT
You have an extraneous comma. It should be:
PlayerID INT NOT NULL AUTO_INCREMENT
Stop putting commas on the next line of your SQL statements as well!
This should work. You had a comma after PlayerID
CREATE TABLE bowling_scores (
PlayerID INT NOT NULL AUTO_INCREMENT,
LName VARCHAR(100) NOT NULL,
FName VARCHAR(100) NOT NULL,
Game1 INT NULL,
Game2 INT NULL,
Game3 INT NULL,
Game4 INT NULL,
PRIMARY KEY (PlayerID)
);
You should be writing something like:
creat table Bowling_score(Playerid int, Firstname varchar(100), Lastname varchar(100), Game1 int, Game2 int, Game3 int);

Error at "unsigned" when creating table in MySQL?

I can't tell what is wrong with this query.
create table roles
(
id int unsigned not null auto_increment
,name varchar(32) not null
,phone varchar(256) not null
,primary key (id)
)
engine=innodb
default charset=utf8;
When I try to run it, I get:
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 'unsigned not null auto_increment ,role_id int unsigned ' at
line 3
Using MySQL 5.7
Thanks for the advice, tadman
Turns out I had a tab between "int unsigned" instead of a space. Replaced the tab with a space and it worked just fine.
That was driving me crazy for almost 2 hours.

Problems Creating tables in MYSQL 5.7

would really like some help trying to figure out what I am doing wrong here. I have searched through several other questions but could not find anything wrong in my CREATE statement that others had.
CREATE TABLE Client(
'Client_ID' INT NOT NULL AUTO_INCREMENT,
'Client_Name' VARCHAR(30) NOT NULL,
'Class' VARCHAR(50) NOT NULL,
'Pre-Billing' BOOLEAN NOT NULL DEFAULT 0,
'Email' VARCHAR(100),
'Phone_Number' VARCHAR(30) NOT NULL,
'Address' VARCHAR(150) NOT NULL,
'Last_Updated' timestamp default now() on update now(),
'Date_Added' timestamp default now(),
PRIMARY KEY ('Client_ID')
);
The error I am getting is
Error Code: 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 ''Client_ID' INT NOT NULL AUTO_INCREMENT, 'Client_Name' VARCHAR (30) NOT NULL, ' at line 2
If you could please advise that would be greatly appreciated, thank you.
If you remove the single quotes around the column names and change the hyphen in "Pre-Billing" to an underscore "Pre_Billing", this should fix it.

#1064 -You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version

I'm new to PHP and MySQL and ran into a little trouble with a learning project I'm working on.
Whenever I try to create a table
CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10) NOT NULL,
type varchar(6) NOT NULL,
notes varchar(512),
receipt int(10),
)
I get the following error message:
#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, type varchar(6) NOT NULL, notes varchar(512),
receipt int(10), ' at line 6**
Here is some info on what I'm working with
Server type: MySQL
Server version: 5.5.32 - MySQL Community Server(GPL)
phpMyAdmin: 4.0.4.1, latest stable version: 4.1.7
I've spent a day knocking my head against the wall over this and now I think its time to ask for help.I was wondering if anyone can tell me what I'm doing wrong?
Remove the comma
receipt int(10),
And also AUTO INCREMENT should be a KEY
double datatype also requires the precision of decimal places so right syntax is double(10,2)
One obvious thing is that you will have to remove the comma here
receipt int(10),
but the actual problem is because of the line
amount double(10) NOT NULL,
change it to
amount double NOT NULL,
In MySQL, the word 'type' is a Reserved Word.
I see two problems:
DOUBLE(10) precision definitions need a total number of digits, as well as a total number of digits after the decimal:
DOUBLE(10,8)
would make be ten total digits, with 8 allowed after the decimal.
Also, you'll need to specify your id column as a key :
CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10,9) NOT NULL,
type varchar(6) NOT NULL,
notes varchar(512),
receipt int(10),
PRIMARY KEY(id) );
I've faced this problem before, the reason behind that for me was the last comma in the schema definition should be deleted if there's no extra columns would be added.
CREATE TABLE users
(
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL, // this comma should be deleted
);
Rule 1: You can not add a new table without specifying the primary key constraint[not a good practice if you create it somehow].
So the code:
CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10,9) NOT NULL,
type varchar(6) NOT NULL,
notes varchar(512),
receipt int(10),
PRIMARY KEY(id));
Rule 2: You are not allowed to use the keywords(words with predefined meaning) as a field name.
Here type is something like that is used(commonly used with Join Types).
So the code:
CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10,9) NOT NULL,
transaction_type varchar(6) NOT NULL,
notes varchar(512),
receipt int(10),
PRIMARY KEY(id));
Now you please try with this code.
First check it in your database user interface(I am running HeidiSQL, or you can try it in your xampp/wamp server also)and make sure this code works. Now delete the table from your db and execute the code in your program.
Thank You.