mysql ERROR 1064 (42000) at line 3: you have an error in your SQL syntax - mysql

I keep getting the following error.
ERROR 1064 (42000) at line 3: 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 '
Species_ID int,
Genus varchar,
Species varchar,
Common_Name varchar,
Indiv' at line 9
hbm248#i6[datasets]$
Here is the full SQL script:
DROP TABLE IF EXISTS paplants;
CREATE TABLE paplants (
ID int NOT NULL AUTO_INCREMENT,
Observation_ID int NOT NULL,
Update_Datetime int NOT NULL,
Site_ID int NOT NULL,
Latitude decimal NOT NULL,
Longitude decimal NOT NULL,
Elevation_in_Meters int,
`State` varchar,
Species_ID int,
Genus varchar,
Species varchar,
Common_Name varchar,
Individual_ID int,
Phenophase_ID int,
Phenophase_Description varchar,
Observation_Date date,
Day_of_Year int,
Phenophase_Status int,
PRIMARY KEY(ID)
);
LOAD DATA LOCAL INFILE "observation_data.csv"
INTO TABLE paplants
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
(ID, Observation_ID, Update_Datetime, Site_ID, Latitude, Longitude, Elevation_in_Meters, `State`, Species_ID, Genus, Species, Common_Name, Individual_ID, Phenophase_ID, Phenophase_Description, Observation_Date, Day_of_Year, Phenophase_Status);
Any help would be really appreciated!

You need to specify a length to your varchar fields. ie: varchar(10) for a varchar field of maximum length 10.

Related

SQL syntax error; "check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Order INT NOT NULL' [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 using MariaDB and MySQL and I'm trying to create a table using the command prompt but I'm getting a syntax error and I am unsure what is wrong. Below is the 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 'Order INT NOT NULL,
FName VARCHAR(255),
LName VARCHAR(255),
PhoneNum VARCH...' at line 3
Here is what I have:
CREATE DATABASE projecttestDB;
USE projecttestDB;
DROP TABLE IF EXISTS Staff;
CREATE TABLE Staff (
Year INT NOT NULL,
Order INT NOT NULL,
FName VARCHAR(255),
LName VARCHAR(255),
PhoneNum VARCHAR(255),
Salary INT,
CHECK(Salary>=0),
PRIMARY KEY (Year, Order)
);
order is a reserved word in SQL. If you absolutely have to use it, you can escape the column name using backticks:
CREATE TABLE Staff (
Year INT NOT NULL,
`Order` INT NOT NULL, -- Here!
FName VARCHAR(255),
LName VARCHAR(255),
PhoneNum VARCHAR(255),
Salary INT,
CHECK(Salary>=0),
PRIMARY KEY (Year, `Order`) -- And here
);
But it's probably a better idea to rename it to something that isn't a reserved word, such as order_num:
CREATE TABLE Staff (
Year INT NOT NULL,
Order_Num INT NOT NULL,
FName VARCHAR(255),
LName VARCHAR(255),
PhoneNum VARCHAR(255),
Salary INT,
CHECK(Salary>=0),
PRIMARY KEY (Year, Order_Num)
);
Order is a system key word. If you change it to something else it will work.

I am not able to change the data type of an already existing table in SQL

CREATE TABLE Employee (
emp_id SMALLINT PRIMARY KEY,
first_name VARCHAR(20) NOT NULL,
last_name VARCHAR (20),
birth_date DATE NOT NULL,
sex VARCHAR (20),
salary INT,
super_id INT,
branch_id SMALLINT
);
ALTER TABLE Employee
ALTER COLUMN sex VARCHAR(1);
I am a beginner so go easy on me, please. I am not able to understand what am I doing wrong.
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 'VARCHAR(1)' at line 2
in mysql you need to use MODIFY
ALTER TABLE Employee
MODIFY COLUMN sex VARCHAR(1);
by the way if you already have data in your table , any value more than 1 character in sex column will be truncated , so you have to take care of that before altering column length

php mysql "unique" error when table is created

So I have this:
CREATE TABLE activeSessions (
id VARCHAR NOT NULL UNIQUE,
claimtime int,
mp FLOAT
);
When I put this into the database, this comes up:
#1064 - 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 UNIQUE,
claimtime int,
mp FLOAT
)' at line 2
How do I fix this?
You need to specify the constraint after the column declaration:
CREATE TABLE activeSessions (
id VARCHAR(10) NOT NULL,
claimtime int,
mp FLOAT,
UNIQUE(id)
);
Remember to give an INT value to the VARCHAR column.

mysql error referring to Null

$sql1= "CREATE TABLE bookapp(
id int NOT NULL AUTO_INCREMENT,
name VARCHAR(30),
pnumber int(11),
emailID VARCHAR(50),
reg_date datetime()
PRIMARY KEY(id)
)";
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 ''', NULL)' at line 1
You can use the following to create the table:
CREATE TABLE bookapp(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(30),
pnumber INT(11),
emailID VARCHAR(50),
reg_date DATETIME,
PRIMARY KEY(id)
);
Explanation:
( and ) on DATETIME is invalid. DATETIME doesn't need a length.
You have to seperate the column definitions with ,. You forgot this after column reg_date.
Hint (to your error message):
Your given CREATE TABLE throws another error message, that is different to yours:
Error Code: 1064. 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 ') PRIMARY KEY(id) )' at line 6

error 10064 mysql 4200 while trying to create table

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.