error 10064 mysql 4200 while trying to create table - mysql

CREATE TABLE DIAMOND(
RAPNETSELLERCODE VARCHAR(30) ,
SHAPE VARCHAR(15) ,
WEIGHT INT(5) ,
COLOR VARCHAR(3) ,
CLARITY VARCHAR(6) ,
CUTGRADE VARCHAR(10),
POLISH VARCHAR(13),
SYMMENTRY VARCHAR(10),
FLUORESCE VARCHAR(10),
MEASUREMENTS INT(100),
MEASLENGTH INT(30),
MEASWIDTH INT(30),
MEASDEPTH INT(30),
RATIO INT(12),
LAB VARCHAR(10),
ID INT(15),
STOCK# VARCHAR(14),
RAPNETPRICE INT(15),
RAPNETDISCOUNTPRICE INT(15),
RAPTOTALPRICE INT(16),
DEPTH % INT(12),
TABLE % INT(10),
GIRDLE VARCHAR(10),
CULET VARCHAR(10),
CERTIFICATEURL VARCHAR(300),
RAPNETLOT # INT(38);
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 ')
CREATE TABLE DIAMOND(
RAPNETSELLERCODE VARCHAR(30) ,
SHAPE VARCHAR(15) ,' at line 1

Evidently there is more to the query than what you are showing us. Seems like you have something like
CREATE TABLE PLATINUM (
/* fields */
)
CREATE TABLE DIAMOND (
You need a semicolon after the ) before CREATE TABLE DIAMOND.
You have other errors in this CREATE TABLE statement as well.
STOCK # -- invalid syntax
`STOCK #` -- desired syntax
Same is true of DEPTH %, TABLE %, and RAPNETLOT #
Finally, you are missing the closing paren for the entire CREATE TABLE statement.

Several things I can see: you have a % symbol in 2 lines of code, you have a # symbol in 2 lines of code, you have DEPTH and TABLE as column names although they are keywords, and you never closed your parenthesis inside the semicolon. At least one of these things is causing the error message. Start with the ) you are missing.

Related

How to fix this mysql create table syntax error [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 1 year ago.
I'm getting a mysql create table syntax error and hoping someone can spot it before I loose my sanity.
create table buyer_representations (
Key int not null auto_increment,
Client_ID int not null,
Start_Time varchar(5),
Start_Date date,
End_Date date,
Property_Type varchar(255),
Geographic_Location varchar(255),
Commission varchar(255),
Alternate_Commission varchar(255),
Lease_Commission varchar(255),
Holdover varchar(255),
Clauses varchar(2000),
primary key (Key)
);
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 'int not null auto_increment,
Client_ID int not null,
Start_Time varchar(5),
Star' at line 2
mysql Ver 14.14 Distrib 5.7.29, for Linux (x86_64) using EditLine wrapper
I tried adding 'primary key' at the end of line 2, as well a default value, and switching up 'not null' with 'auto_increment' .. but nothing is working.
Edit:
I also tried changing Key to KeyId, and putting Key in quotes .. but the error remains the same.
Final Edit:
putting Key inside backquotes finally worked
create table buyer_representations (
`Key` int not null auto_increment,
Client_ID int not null,
Start_Time varchar(5),
Start_Date date,
End_Date date,
Property_Type varchar(255),
Geographic_Location varchar(255),
Commission varchar(255),
Alternate_Commission varchar(255),
Lease_Commission varchar(255),
Holdover varchar(255),
Clauses varchar(2000),
primary key (`Key`)
);
Key is a reserve keyword, rename that and you should be golden.
A complete list of keywords and reserved words can be found in section 10.3 Keywords and Reserved Words. Below
https://dev.mysql.com/doc/refman/8.0/en/keywords.html
in your case, this should work (I name it test, but rename it to whatever fits your situation)
create table buyer_representations (
test int not null auto_increment,
Client_ID int not null,
Start_Time varchar(5),
Start_Date date,
End_Date date,
Property_Type varchar(255),
Geographic_Location varchar(255),
Commission varchar(255),
Alternate_Commission varchar(255),
Lease_Commission varchar(255),
Holdover varchar(255),
Clauses varchar(2000),
primary key (test)
);
The problem is the column name you have used in your table.
The first column name is Key.
Key is considered as a reserved word in Mysql and it has a special meaning. That is why there is an error.
If you want to use the same column name you can do it by writing the column name inside ``.
For eg.
create table buyer_representations (
`Key` int not null auto_increment,
This will work fine.

Why am I getting error at line 1 on Create Table

First time working with MySQL. Using MySQL Workbench with a new instance installed on my Windows 10 desktop. I've created a test test db/schema, and now trying to create a table.
CREATE TABLE kcplusers (
'user_barcode' varchar(255),
'first_name' varchar(255),
'middle_name' varchar(255),
'last_name' varchar(255),
'address_street' varchar(500),
'city_state' varchar(500),
'zip' varchar(100),
'user_profile' varchar(500),
'birth_date' DATE
);
Workbench shows a red x at line 1 and red slashes under the open-parenth (
I get the error:
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 ''user_barcode' varchar(255), 'first_name' varchar(255), 'middle_name' varc' at line 2
What am I missing?
Don't use single quotes ' for the fields names, use backticks ` or nothing at all:
CREATE TABLE kcplusers (
`user_barcode` varchar(255),
`first_name` varchar(255),
`middle_name` varchar(255),
`last_name` varchar(255),
`address_street` varchar(500),
`city_state` varchar(500),
`zip` varchar(100),
`user_profile` varchar(500),
`birth_date` DATE
);
You're using apostrophes around the column names - they should be removed in this case.
If you must specify certain characters in a column name you can use ascii cd 96 shown as ` - usually just to the left of the number "1" on your keyboard.
But to keep it simple as you're starting out - just remove the apostrophes.
And let us know how it turns out (good or bad)
Cheers!

SQL query doesn't work?

I want to create a table in the database and below is the query that I wrote; does anyone have any idea why it doesn't work?
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 'sname varchar(255), city varchar(255), avg int(20), clg# int(20) )' at line 4`
CREATE TABLE stud
(
s# int,
sname varchar(255),
city varchar(255),
avg int(20),
clg# int(20)
);
The # is not a valid character for an identifier. Just remove it:
CREATE TABLE stud (
s int,
sname varchar(255),
city varchar(255),
avg int(20),
clg int(20)
);
You can review the rules for identifiers here. Note you could also put the name in backticks:
`s#` int,
However, I strongly discourage you from using names that need to be escaped.
You cannot use the '#' character in column names.
you cant have # in your table names, change your script to this one and try again.
CREATE TABLE stud ( s int,
sname varchar(255),
city varchar(255),
avg int(20),
clg int(20) );
It's not recommended to use '#' to name your identifiers. This is ambiguous for you and other developers on your team. Use this instead
CREATE TABLE stud (
sNo int,
sname varchar(255),
city varchar(255),
avg int(20),
clgNo int(20)
);
By naming your identifiers descriptively it easier for everyone to understand. However mysql qouted identifier naming rules allow ASCII: U+0001 .. U+007F
see here.
MySQL Schema object naming Rules

SQL syntax error in this part: "int not null auto_increment,"

I create a physical model in powerdesigner
and then generate the code for mysql5, and now in
phpmyadmin Im getting an 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 'create table CARD
Do you see why this can be happening?
Im creating my tables like this:
create table books
(
COD_BOOK int not null auto_increment,
TITLE_BOOK varchar(50),
ISBN _BOOK varchar(20),
CATEGORY_BOOK varchar(20),
primary key (COD_BOOK)
)
And the problem seems like is in this part: int not null auto_increment,
You're missing the semi-colon at the end of your create statement. This makes the first line of the create statement for the next table an error which is what that error message is trying to tell you.
create table books
(
COD_BOOK int not null auto_increment,
TITLE_BOOK varchar(50),
ISBN_BOOK varchar(20),
CATEGORY_BOOK varchar(20),
primary key (COD_BOOK)
);
The problem is the space after ISBN:
create table books
(
COD_BOOK int not null auto_increment,
TITLE_BOOK varchar(50),
ISBN_BOOK varchar(20),
CATEGORY_BOOK varchar(20),
primary key (COD_BOOK)
)
Here is a SQL Fiddle.

what is wrong with the sql query?

CREATE TABLE 1
(text longtext(4,294,967,295),
date VARCHAR(50),
time VARCHAR(50),
id INT(11 ) NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY ( `id` )
What is wrong with the above SQL statement? I keep getting an 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 '(4,294,967,295), date VARCHAR(50), time VARCHAR(50), id INT( 11 ) NOT NULL AU' at line 3
1 is a lousy name for a table. If you use it, you need to escape the name. Also, commas aren't allow in lengths for character fields and longtext doesn't need a length anyway:
CREATE TABLE `1`
(text longtext,
date VARCHAR(50),
time VARCHAR(50),
id INT(11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY
)
And, you don't "add" a primary key. You just declare it.