#1064 error message - SQL syntax [duplicate] - mysql

This question already has answers here:
How can I fix MySQL error #1064?
(3 answers)
Closed 8 years ago.
All I am trying to do is create a simple database to store user information they submit off my website.
Here is my code:
USE database_1;
CREATE TABLE contact_us (
`id` INT NOT NULL AUTO_INCREMENT,
`fname` VARCHAR(30) NOT NULL,
`lname` VARCHAR(30) NOT NULL,
`coName` VARCHAR(50) NOT NULL,
`phone` VARCHAR(11) NOT NULL,
`ext` VARCHAR(10) NOT NULL,
`street` VARCHAR(50) NOT NULL,
`city` VARCHAR(30) NOT NULL,
`state` VARCHAR(30) NOT NULL,
`zip` VARCHAR(10) NOT NULL,
`email` VARCHAR(50) NOT NULL,
`website` VARCHAR(50) NOT NULL,
`inquiry` VARCHAR NOT NULL,
PRIMARY KEY(id)
) ENGINE=INNODB;
Here is my 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, PRIMARY KEY(id)
) ENGINE=INNODB' at line 14
I have checked/tried to make sure all commas and semicolons were in place, added a space between PRIMARY KEY (id), adding a space between ENGINE = INNODB;, and moving ENGINE=INNODB; down to its own line. I have looked over a ton of forums to see if I could figure it out myself but everything I have tried hasn't resolved my error.
If anyone out there as any idea what I am doing wrong, your help would be greatly appreciated. Thank You

replace this
`inquiry` VARCHAR NOT NULL,
by
`inquiry` VARCHAR(25) NOT NULL,
you have to give VARCHAR LENGTH, i writed 25 you have to choose your length

Replace
`inquiry` VARCHAR
with
`inquiry` VARCHAR(XX)
where XX is the fixed (max) length of the inquiry field, or with
`inquiry` LONGTEXT
if the inquiry field should store a text of arbitrary length.

Related

Maria DB Server

I land up in an error stating:
Error Code 1064: You have an error in your sqlsyntax; check the manual that corresponds to your MariaDB Server syntax for the right syntax to use
CREATE TABLE 'company'.'employee'(
'fname' VARCHAR (10) NOT NULL,
'mname' VARCHAR(2) NULL,
'lname' VARCHAR(10) NOT NULL,
'ssn' CHAR(9) NOT NULL,
'bdate' DATE,
'address' VARCHAR(20) NOT NULL,
'sex' CHAR NULL,
'salary' DECIMAL (10, 2) NULL,
'super_ssn' CHAR(9) NULL,
'd_no' INT NOT NULL,
PRIMARY KEY ('ssn'));
Use ` instead of ' (single quote),
You should write it like the following :
CREATE TABLE `company`.`employee`(
`fname` VARCHAR (10) NOT NULL,
`mname` VARCHAR(2) NULL,
`lname` VARCHAR(10) NOT NULL,
`ssn` CHAR(9) NOT NULL,
`bdate` DATE,
`address` VARCHAR(20) NOT NULL,
`sex` CHAR NULL,
`salary` DECIMAL (10, 2) NULL,
`super_ssn` CHAR(9) NULL,
`d_no` INT NOT NULL,
PRIMARY KEY (`ssn`)
);
Actually, the ` symbol is optional, but it is used if the field names, tables, or databases are the same as keywords or MySQL clauses whose purpose is that MySQL is not confused with what you mean in the query.
For example :
SELECT column FROM `char`
I use ` symbol because the name of the table is the same as keyword on MySQL i.e CHAR() (but naming like that is a bad way), so keep in mind that if you write SQL Query you must decide to use the ` symbol
hope this can help you.

What is wrong with my code for phpmyadmin?

I tried to make a database is phpmyadmin, but I keep 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 '0) NULL,
Datum Verkocht DATE NULL,
Personeel VARCHAR(30) NULL,
`Min' at line 9
That's for this code
CREATE TABLE `veilingen`.`Veilingen`(
`Nr` INT(3) NOT NULL,
`Artikel` VARCHAR(100) NULL,
`Datum Geveild` DATE NULL,
`Tel. Verkoper` INT(10) NULL,
`Datum Ingeleverd` DATE NULL,
`Kast`
SET
(0) NULL,
`Datum Verkocht` DATE NULL,
`Personeel` VARCHAR(30) NULL,
`Minimum` DECIMAL NULL,
`Koop Nu` DECIMAL(100) NULL,
`Geveild Voor` DECIMAL(100) NULL,
`Betaald` ENUM(0) NULL,
`Cadeaubon` DECIMAL(100) NULL,
`Versturen` VARCHAR(100) NULL,
`Opmerkingen` VARCHAR(100) NULL,
PRIMARY KEY(`Nr`(1))
) ENGINE = MyISAM;
Sorry for the mess, I can't get the code span to work.
Can somebody help me?
Following is the right syntax for create table in php, you can edit this code according to your table name,column name and it's datatype.
CREATE TABLE employee (
empId int(11) NOT NULL AUTO_INCREMENT,
empName varchar(255) NOT NULL,
empDept varchar(255) NOT NULL,
PRIMARY KEY (empId)
)

#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 [duplicate]

This question already has answers here:
How can I add comments in MySQL?
(6 answers)
Closed 6 years ago.
I need some help below, I am getting this error please help me with the solution.
SQL query:
===EMPLOYEE===
------- Table Structure For Job Seeker----------
CREATE TABLE `employees`(
`ee_id` int(4) NOT NULL auto_increment,
`ee_email` varchar(64) NOT NULL,
`ee_password` varchar(64) NOT NULL,
`ee_fname` varchar(30) NOT NULL,
`ee_lname` varchar(30) NOT NULL,
`ee_day` varchar(10) NOT NULL,
`ee_month` varchar(10) NOT NULL,
`ee_year` varchar(10) NOT NULL,
`ee_gender` varchar(30) NOT NULL,
`ee_address` varchar(256) NOT NULL, /*Address newly added.*/
`ee_country` varchar(130) NOT NULL,
`ee_city` varchar(30) NOT NULL,
`ee_education` varchar(20) NOT NULL,
`ee_master` varchar(20) NOT NULL,
`ee_mcode` varchar(10) NOT NULL,
`ee_mnumber` varchar(30) NOT NULL,
`ee_experience` varchar(30) NOT NULL,
`ee_skills` varchar(130) NOT NULL,
`ee_industry` varchar(130) NOT NULL,
`ee_certification` varchar(130) NOT NU[...]
Below is what I am getting as 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
'======================================EMPLOYEE==================================' at line 1
You can't just lob text with = wherever you please in your script. Comments need to start with two dashes (--). So you could, for instance, have you file's header as so:
--- Employee ---

Im getting an error when creating my database (#1064)

I was trying to create a database using phpmyadmin but I keep on getting 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 ') NOT NULL,First Name VARCHAR(30) NOT NULL,Last Name VARCHAR(30) NOT' at line 3
Im using Tomcat version 8.0. Below is the query I am Executing
CREATE TABLE `cs485_lab5`.`Orders` (
`Item Number` VARCHAR(20) NOT NULL,
`Price` DOUBLE(10) NOT NULL,
`First Name` VARCHAR(30) NOT NULL,
`Last Name` VARCHAR(30) NOT NULL,
`Shipping Address` VARCHAR(50) NOT NULL,
`Credit Card` VARCHAR(20) NOT NULL,
`CCN` INT(16) NOT NULL,
PRIMARY KEY (`Credit Card`)
) ENGINE = InnoDB;
Don't specify a length for DOUBLE. Also, if you are designing the table, don't put spaces in the column names. Use names that don't need escaping. Having to use escape characters just clutters up queries unnecessarily.
So:
CREATE TABLE Orders (
`ItemNumber` VARCHAR(20) NOT NULL,
`Price` DOUBLE NOT NULL,
`FirstName` VARCHAR(30) NOT NULL,
`LastName` VARCHAR(30) NOT NULL,
`ShippingAddress` VARCHAR(50) NOT NULL,
`CreditCard` VARCHAR(20) NOT NULL,
`CCN` INT(16) NOT NULL,
PRIMARY KEY (`CreditCard`)
) ENGINE = InnoDB;
Here is a SQL Fiddle.

Error trying to create table in MySQL via terminal

I am trying to create a table in my database via terminal.
Here is my syntax:
CREATE TABLE `users` (
PRIMARY KEY(id) NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR NOT NULL,
`first_name` VARCHAR NOT NULL,
`gender` VARCHAR NOT NULL,
`fav_color` VARCHAR NOT NULL,
`birthdate` DATE NOT NULL
);
I am getting 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 to use near 'NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR NOT NULL,
`first_name` VARCHA' at line 2
What am i dong wrong here?
Besides the issues that Jens and Marc pointed out, You have to declare the length of your Varchar fields in order for this statement to work, like so:
CREATE TABLE `test`.`users` (
`id` INT NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR(45) NOT NULL,
`first_name` VARCHAR(45) NOT NULL,
`gender` VARCHAR(45) NOT NULL,
`fav_color` VARCHAR(45) NOT NULL,
`birthdate` DATE NOT NULL,
PRIMARY KEY (`id`));
the syntax of your create statement is wrong:
the correct one is this:
CREATE TABLE `users` (
`id` int NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR(255) NOT NULL,
`first_name` VARCHAR(255) NOT NULL,
`gender` VARCHAR(255) NOT NULL,
`fav_color` VARCHAR(255) NOT NULL,
`birthdate` DATE NOT NULL,
PRIMARY KEY(`id`)
);
For more Information see the offical documentation.
it should be
id int primary key auto_increment not null
You're trying to define a primary key on a field that doesn't exist. Keys cannot be "not null" and definitely cannot be "auto_increment".