Error in MySQL query - mysql

CREATE TABLE questions
(
qid INT AUTO_INCREMENT,
submitterId VARCHAR(8) NOT NULL,
approverId VARCHAR(8) NOT NULL,
questionText TEXT NOT NULL UNIQUE,
answerA VARCHAR(100) NOT NULL,
answerB VARCHAR(100) NOT NULL,
answerC VARCHAR(100) NOT NULL,
answerD VARCHAR(100) NOT NULL,
difficulty INT NOT NULL,
category INT NOT NULL,
correctAnswer INT NOT NULL,
selectionProb INT NOT NULL,
status INT NOT NULL
);
What is wrong with the above SQL command in MySQL?
im getting
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 'TABLE
 questions
(
qid INT AUTO_INCREMENT,
submitterId VARCHAR(8) NOT NULL,
appr' at line 1

There can be only one auto column and it must be defined as a key.
BLOB/TEXT columns in key specification can't be used without a key length.
Thus, the correct SQL DDL shall be:
CREATE TABLE questions (
qid INT AUTO_INCREMENT PRIMARY KEY,
submitterId VARCHAR(8) NOT NULL,
approverId VARCHAR(8) NOT NULL,
questionText TEXT NOT NULL,
answerA VARCHAR(100) NOT NULL,
answerB VARCHAR(100) NOT NULL,
answerC VARCHAR(100) NOT NULL,
answerD VARCHAR(100) NOT NULL,
difficulty INT NOT NULL,
category INT NOT NULL,
correctAnswer INT NOT NULL,
selectionProb INT NOT NULL,
status INT NOT NULL
);

An idtentity-column must be declared as PRIMARY or UNIQUE

Add PRIMARY KEY (qid) at the end of your query.

Make your AUTO INCREMENT NOT NULL and add PRIMARY KEY at the end.
CREATE TABLE questions
(
qid INT AUTO_INCREMENT NOT NULL,
submitterId VARCHAR(8) NOT NULL,
approverId VARCHAR(8) NOT NULL,
questionText TEXT NOT NULL,
answerA VARCHAR(100) NOT NULL,
answerB VARCHAR(100) NOT NULL,
answerC VARCHAR(100) NOT NULL,
answerD VARCHAR(100) NOT NULL,
difficulty INT NOT NULL,
category INT NOT NULL,
correctAnswer INT NOT NULL,
selectionProb INT NOT NULL,
status INT NOT NULL,
PRIMARY KEY (qid)
);

Related

#1064-you have an error in SQL syntax: check the manual that corresponds to your MySQL server version for the right syntax to use near ')

create TABLE product
(
productid int not null AUTO_INCREMENT,
productname varchar(100) not null,
productdesc varchar(100)not null,
productrate double(100) not null,
imagea varchar(100) not null,
imageb varchar(100) not null,
imagec varchar(100) not null
) type=MyISAM
these images contains query and the error displayed
create TABLE product
(
productid int not null AUTO_INCREMENT,
productname varchar(100) not null,
productdesc varchar(100)not null,
productrate float(25) not null,
imagea varchar(100) not null,
imageb varchar(100) not null,
imagec varchar(100) not null,
PRIMARY KEY(productid)
) ENGINE=MyISAM
Thankyou Craig and thank you for all for replying me to solve this.

have an error when creating a table in phpmyadmin mysql

i need to create a table and this the SQL queries
CREATE TABLE person {
per_id int(10) not null AUTO_INCREMENT,
name varchar(256) not null,
clth_color varchar(256) not null,
per_photo varchar(256) not null,
age varchar(10) not null,
description text not null,
loaction varchar(256) not null,
type int(1) not null,
user_id int(10) not null,
primary key(per_id),
foreign key(user_id) references users(user_id)
};
but i get 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 '{
per_id int(10) not null AUTO_INCREMENT,
name varchar(256) not null,
' at line 1
Try using () instead {}
CREATE TABLE person (
per_id int(10) not null AUTO_INCREMENT,
name varchar(256) not null,
clth_color varchar(256) not null,
per_photo varchar(256) not null,
age varchar(10) not null,
description text not null,
loaction varchar(256) not null,
type int(1) not null,
user_id int(10) not null,
primary key(per_id),
foreign key(user_id) references users(user_id)
);
I'm not entirely sure but it might work.

MySQL: How to create table with auto incrementing column via script

I am new to MySQL and hope someone can help me with this.
I want to create a simple table with two special settings:
a two-column primary key including the columns "de" and "location"
an auto incrementing column "tID" that generates a unique ID,
starting with 1
I tried the following (and several other approaches) but this always returns the below error:
The SQL:
CREATE TABLE TranslationsMain (
de VARCHAR(100) NOT NULL,
tID INT UNSIGNED NOT NULL AUTO_INCREMENT,
location VARCHAR(50) NOT NULL,
classes VARCHAR(100) NOT NULL,
info VARCHAR(100) NOT NULL,
sortOrder INT NOT NULL,
en VARCHAR(100) NOT NULL,
PRIMARY KEY(de, location)
)
The error message:
"Incorrect table definition; there can be only one auto column and it must be defined as a key."
It works if I leave the auto incrementing column ("tID") out so there seems to be something wrong here.
Can someone help me with this ?
Many thanks in advance,
Mike
Try below query, I think this will solve your problem
CREATE TABLE TranslationsMain (
de VARCHAR(100) NOT NULL,
tID INT UNSIGNED NOT NULL AUTO_INCREMENT,
location VARCHAR(50) NOT NULL,
classes VARCHAR(100) NOT NULL,
info VARCHAR(100) NOT NULL,
sortOrder INT NOT NULL,
en VARCHAR(100) NOT NULL,
PRIMARY KEY(tID),
UNIQUE(de, location))
OR
CREATE TABLE TranslationsMain12 (
de VARCHAR(100) NOT NULL,
tID INT UNSIGNED NOT NULL AUTO_INCREMENT,
location VARCHAR(50) NOT NULL,
classes VARCHAR(100) NOT NULL,
info VARCHAR(100) NOT NULL,
sortOrder INT NOT NULL,
en VARCHAR(100) NOT NULL,
unique(tID),
primary key(de,location)
)
In your SQL what the problem is auto increment must be primary key. Otherwise it will not work.
You can use like these. i think your problem will solve.
CREATE TABLE TranslationsMain (
de VARCHAR(100) NOT NULL,
tID INT UNSIGNED NOT NULL AUTO_INCREMENT,
location VARCHAR(50) NOT NULL,
classes VARCHAR(100) NOT NULL,
info VARCHAR(100) NOT NULL,
sortOrder INT NOT NULL,
en VARCHAR(100) NOT NULL,
PRIMARY KEY(tID,de, location))

phpmyadmin showing mysql error when creating table?

Im trying to create a table using the following query.phpmyadmin does not allow it.What im i doing wrong
CREATE TABLE main (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY(id),
dealername VARCHAR(32) NOT NULL,
product VARCHAR(32) NOT NULL,
type VARCHAR(16) NOT NULL,
date VARCHAR(16) NOT NULL,
desc VARCHAR(255) NOT NULL,
location VARCHAR(32) NOT NULL,
sublocation VARCHAR(32) NOT NULL,
address VARCHAR(255) NOT NULL,
phone1 VARCHAR(16) NOT NULL,
phone2 VARCHAR(16) NOT NULL,
auth VARCHAR(10) NOT NULL,
brands VARCHAR(255) NOT NULL,
lat VARCHAR(32) NOT NULL,
lon VARCHAR(32) NOT NULL
);
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 '(id), dealername VARCHAR(32) NOT NULL, product VARCHAR(32) NOT NULL, type VAR' at line 2
You have to remove (id)
CREATE TABLE main (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
dealername VARCHAR(32) NOT NULL,
product VARCHAR(32) NOT NULL,
type VARCHAR(16) NOT NULL,
date VARCHAR(16) NOT NULL,
`desc` VARCHAR(255) NOT NULL,
location VARCHAR(32) NOT NULL,
sublocation VARCHAR(32) NOT NULL,
address VARCHAR(255) NOT NULL,
phone1 VARCHAR(16) NOT NULL,
phone2 VARCHAR(16) NOT NULL,
auth VARCHAR(10) NOT NULL,
brands VARCHAR(255) NOT NULL,
lat VARCHAR(32) NOT NULL,
lon VARCHAR(32) NOT NULL
);
The syntax of the table create statement is wrong. See the documentation.
The name of the column after Primary key is not expected.
And desc is a reserved word in sql so you have to escape it or better take an other column name.
remove (id)
desc is mysql keyword.
put it in backticks like this, if you still want to use desc as your column name.
CREATE TABLE main (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
dealername VARCHAR(32) NOT NULL,
product VARCHAR(32) NOT NULL,
type VARCHAR(16) NOT NULL,
date VARCHAR(16) NOT NULL,
`desc` VARCHAR(255) NOT NULL,
location VARCHAR(32) NOT NULL,
sublocation VARCHAR(32) NOT NULL,
address VARCHAR(255) NOT NULL,
phone1 VARCHAR(16) NOT NULL,
phone2 VARCHAR(16) NOT NULL,
auth VARCHAR(10) NOT NULL,
brands VARCHAR(255) NOT NULL,
lat VARCHAR(32) NOT NULL,
lon VARCHAR(32) NOT NULL
);

Mysql Syntax error, unexpected NULL_SYM, expecting '('

I am trying to create a table but keep getting this Syntax error: unexpected NULL_SYM, expecting '(' error.
CREATE TABLE `project` (
`project_id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`project_name` varchar NULL,
`location` varchar NULL,
`date` datetime NULL,
`status` varchar NULL,
`specifier` varchar NULL,
`supplier` varchar NULL,
`cost` float NULL,
`sales_amount` float NULL,
`estimate_qty` float NULL,
`unit` varchar NULL,
`proposed_office` varchar NULL,
`proposed_person` int NULL,
`followed_office` varchar NULL,
`followed_person` int NULL,
`remark` varchar NULL,
PRIMARY KEY (`project_id`)
);
The error is at 'project_name' varchar NULL,
You need to specify the length of your varchar columns. Example
`project_name` varchar(100) NULL
It could look like this
CREATE TABLE `project`
(
`project_id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`project_name` varchar(100) NULL,
`location` varchar(100) NULL,
`date` datetime NULL,
`status` varchar(10) NULL,
`specifier` varchar(100) NULL,
`supplier` varchar(100) NULL,
`cost` decimal NULL,
`sales_amount` decimal NULL,
`estimate_qty` decimal NULL,
`unit` varchar(10) NULL,
`proposed_office` varchar(100) NULL,
`proposed_person` int NULL,
`followed_office` varchar(100) NULL,
`followed_person` int NULL,
`remark` varchar(200) NULL,
PRIMARY KEY (`project_id`)
);