phpmyadmin showing mysql error when creating table? - mysql

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
);

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.

how to calculate the number of a table's rows changed(update or insert) in a day on mysql

I have a trade records table and i want to calculate the rows of this table changed including update or insert.
I have check the information_schema in mysql.There is a table called TABLE and it has a column TABLE_ROWS.But i didn't find anything helpful.
well,this table like this
CREATE TABLE pre_actived_apk_record
(
id INT(11) PRIMARY KEY NOT NULL AUTO_INCREMENT,
appid VARCHAR(255) NOT NULL,
channelid VARCHAR(255) NOT NULL,
uid INT(11) NOT NULL,
appname VARCHAR(255) NOT NULL,
packagename VARCHAR(255) NOT NULL,
versioncode VARCHAR(255) NOT NULL,
versionname VARCHAR(255) NOT NULL,
brand VARCHAR(255) NOT NULL,
model VARCHAR(255) NOT NULL,
imei VARCHAR(255) NOT NULL,
sys_version VARCHAR(255) NOT NULL,
mac_address VARCHAR(255) NOT NULL,
imsi VARCHAR(255) NOT NULL,
iccid VARCHAR(255) NOT NULL,
uploadtime INT(11) NOT NULL,
dateline INT(11) NOT NULL,
rule INT(11) NOT NULL,
price INT(11) NOT NULL
);
And i wonder i could use some built-in method to show the result of this table chanaged.

How can I declare a table without primary key?

I am using MySQL Query Browser.
I have tried this code:
CREATE TABLE `something`.`payment_something` (
`firstName` varchar(15) NOT NULL,
`lastName` varchar(15) NOT NULL,
`inputEmail` varchar(55) NOT NULL,
`genderRadios` varchar(15) NOT NULL,
`monthh` varchar(10) NOT NULL,
`dayy` varchar(10) NOT NULL,
`yearr` varchar(10) NOT NULL,
`postalAddress` varchar(15) NOT NULL,
`phoneNumber` varchar(15) NOT NULL,
`ZipCode` varchar(15) NOT NULL,
`CreditCard` varchar(15) NOT NULL,
`expireMonth` varchar(10) NOT NULL,
`expireYear` varchar(10) NOT NULL,
`Institution` varchar(25) NOT NULL,
`textinput` varchar(15) NOT NULL,
`radios` varchar(10) NOT NULL,
PRIMARY KEY ()
) ENGINE=InnoDB DEFAULT CHARSET=greek;
of course it shows error in the PRIMARY KEY line. Any idea?
EDIT Better solution
CREATE TABLE `something`.`payment_something` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`firstName` varchar(15) NOT NULL,
`lastName` varchar(15) NOT NULL,
`inputEmail` varchar(55) NOT NULL,
`genderRadios` varchar(15) NOT NULL,
`monthh` varchar(10) NOT NULL,
`dayy` varchar(10) NOT NULL,
`yearr` varchar(10) NOT NULL,
`postalAddress` varchar(15) NOT NULL,
`phoneNumber` varchar(15) NOT NULL,
`ZipCode` varchar(15) NOT NULL,
`CreditCard` varchar(15) NOT NULL,
`expireMonth` varchar(10) NOT NULL,
`expireYear` varchar(10) NOT NULL,
`Institution` varchar(25) NOT NULL,
`textinput` varchar(15) NOT NULL,
`radios` varchar(10) NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=greek;
It shows wrong in the PRIMARY KEY line why?
Simply exclude the problematic line:
PRIMARY KEY ()
You don't need to have that line, if you are not actually defining a key. In your example, you will also have to remove the comma directly preceding this line, of course.
UPDATE:
In your updated example, just take the '' off of 'id' when you declare it. Use the backtick (`), instead of the apostrophe:
PRIMARY KEY (`id`)

Error in MySQL query

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)
);