#1064 - You have an error in your SQL syntax; [closed] - mysql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have been trying to create the following table on mySQL 5.6
CREATE TABLE customers
(
id INTEGER NOT NULL auto_increment,
cust_first_name VARCHAR (30) NOT NULL,
cust_last_name VARCHAR (30) NOT NULL,
cust_address VARCHAR (30),
cust_dob DATE,
cust_anniversary DATE,
cust_phone1 INTEGER(10) NOT NULL,
cust_phone2 INTEGER(10),
cust_phone3 INTEGER(10),
cust_fax INTEGER(10),
cust_email VARCHAR,
cust_PW VARCHAR(10) NOT NULL,
cust_suburb VARCHAR(20),
cust_postcode VARCHAR(4),
cust_state VARCHAR (3),
cust_gender CHAR(1) NOT NULL,
cust_type VARCHAR(5) NOT NULL,
companies_id INTEGER NOT NULL,
employees_id INTEGER NOT NULL,
PRIMARY KEY (id),
CONSTRAINT com_cust_FK FOREIGN KEY (companies_id) REFERENCES companies(id),
CONSTRAINT emp_cust_FK FOREIGN KEY (employees_id) REFERENCES employees(id),
CHECK (cust_gender IN('M','F')),
CHECK (cust_type IN(‘Gold’,’Silver’,’Bronze’)
);
And I get the following 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 ' cust_Password VARCHAR(10) NOT NULL, cust_suburb VARCHAR(20), cust_postcod' at line 13
How can i overcome this?

mention VARCHAR(150) field size to cust_email field

Related

Why does my SQL gave an error when i am using VARCHAR as primary key? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
This is my code
CREATE TABLE mactor(
pid VARCHAR(30) UNSIGNED NOT NULL AUTO_INCREMENT,
fname VARCHAR(30) NOT NULL,
lname VARCHAR(30) NOT NULL,
gender VARCHAR(20) NOT NULL,
PRIMARY KEY (pid));
and this is the error
#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 'UNSIGNED NOT null AUTO_INCREMENT,
fname VARCHAR(30) NOT NULL,
lname...' at line 2.
I am very confused and I don't want to use any other values as my primary key other than VARCHAR. please help!
Remove the UNSIGNED; unsigned can only apply to numeric types, not character or binary types. You will also need to get rid of AUTO_INCREMENT; you can't auto increment a character type.

When I try to access or create tables I get an error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
CREATE TABLE demos
(id INT UNSIGNED AUTO_INCREMENT PRIMARY_KEY
first_name VARCHAR NOT NULL
last_name VARCHAR NOT NULL
hometown VARCHAR NOT NULL)
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 'first_name
VARCHAR NOT NULL last_name VARCHAR NOT NULL hometown VARCHAR NOT...' at line 3
You need to
separate the field definitions with commas;
PRIMARY KEY should be two words separated by a space, not joined with an underscore;
VARCHAR fields need to have a length specified
The following works fine with both MySQL (which you said you're using) and MariaDB (which the error message says you're using):
CREATE TABLE demos
(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(10) NOT NULL,
last_name VARCHAR(10) NOT NULL,
hometown VARCHAR(10) NOT NULL)
db<>fiddle here
You need to add commas after each field in your table, like so:
CREATE TABLE demos (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(10) NOT NULL,
last_name VARCHAR(10) NOT NULL,
hometown VARCHAR(10) NOT NULL
);
EDIT: As the other answer suggests, you also need to specify the default VARCHAR size and separate the keywords PRIMARY and KEY

You have an error in your SQL syntax [MariaDB] [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm getting this error while developing a javaEE application with MariaDB.
The error is:
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 'STARTING DATE, TITLE VARCHAR(255), CREATOR VARCHAR(255), LOCATION BIGINT, FORECA' at line 1
This is the problematic query:
CREATE TABLE EVENT
(
ID VARCHAR(255) NOT NULL,
DESCRIPTION VARCHAR(255),
ENDING DATE,
ISALLDAY TINYINT(1) default 0,
PUBLICEVENT TINYINT(1) default 0,
STARTING DATE,
TITLE VARCHAR(255),
CREATOR VARCHAR(255),
LOCATION BIGINT,
FORECAST BIGINT,
PRIMARY KEY (ID);
I can't figure out what is the problem...
You have a two typos:
STARTING - is a reserved word - use backticks
you forget closing parenthesis
This script should work:
CREATE TABLE EVENT
(
ID VARCHAR(255) NOT NULL,
DESCRIPTION VARCHAR(255),
ENDING DATE,
ISALLDAY TINYINT(1) default 0,
PUBLICEVENT TINYINT(1) default 0,
`STARTING` DATE,
TITLE VARCHAR(255),
CREATOR VARCHAR(255),
LOCATION BIGINT,
FORECAST BIGINT,
PRIMARY KEY (ID)
);

Error #1064 mysql when creating table [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I tried to find out why this error is keep showing when i create the DB.
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
'NUMBER(10) not null,
email varchar(50) not null,'
at line 4
here is the table that has the error:
create table students
(
name varchar(30) not null,
studentID NUMBER(10) not null,
email varchar(30) not null,
mobile NUMBER(15) not null,
GPA DOUBLE not null,
courseID varchar(6) not null,
membershipType varchar
groupID NUMBER
finalMark number
Check (courseID='SWE496' OR courseID = 'SWE497')
primary key (id)
);
There are quite a few errors here:
There is no such thing as NUMBER. Use NUMERIC or DECIMAL.
You are missing commas after the lines for membershipType, groupID, finalMark and Check.
membershipType is a varchar, but you didn't specify the length.
There is no field called "id", though you are trying to declare it as the primary key
This will work:
CREATE TABLE students
(
id INTEGER AUTO_INCREMENT NOT NULL,
NAME VARCHAR(30) NOT NULL,
studentID NUMERIC(10) NOT NULL,
email VARCHAR(30) NOT NULL,
mobile DECIMAL(15) NOT NULL,
GPA DOUBLE NOT NULL,
courseID VARCHAR(6) NOT NULL,
membershipType VARCHAR(10),
groupID DECIMAL,
finalMark DECIMAL,
CHECK (courseID='SWE496' OR courseID = 'SWE497'),
PRIMARY KEY (id)
);

How to create TINYINT(1) datatype in mysql database? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm creating table in mysql database but it is giving error...
CREATE TABLE IF NOT EXISTS `EC_TIMETABLE` (
`S_ID` VARCHAR(30) NOT NULL PRIMARY KEY,
`SKILLSET_ID` VARCHAR(30) NULL ,
START_DT DATETIME NULL,
END_DT DATETIME NULL,
REPEAT TINYINT(1) NULL,
ALL_DAY TINYINT(1) NULL,
CLASS_DURATION INT NULL,
COURSE_DURATION INT NULL,
REPEAT_TYPE VARCHAR(30) NULL,
REPEAT_EVERY INT NULL,
REPEAT_DAYS VARCHAR(100) NULL,
REPEAT_FROM DATE NULL,
REPEAT_TO DATE NULL,
COURSE_FEE INT NULL,
ATTENDEE_MIN INT NULL,
ATTENDEE_MAX INT NULL,
SEARCH_KEY TINYTEXT NULL,
FOREIGN KEY (`SKILLSET_ID` )
REFERENCES `EC_SKILLSET` (`S_ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
But it giving 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 'REPEAT TINYINT(1) NULL, ALL_DAY TINYINT(1) NULL, CLASS_DURATION
INT NULL' at line 6
How to solve this one..
REPEAT is a Reserved Keyword. You can still use it but you need to wrap it with backticks.
`REPEAT` TINYINT(1) NULL,
MySQL Reserved Keywords List
I suggest that you don't use such keywords on the reserve list to avoid neck pain in the future.
I believe REPEAT is a keyword in MySQL. Try renaming your column.
First you shouldn't use REPEAT because this is reserved by mysql and secondly take a look at MySql Error 150 - Foreign keys because you have another error concerning foreign keys.