Continually getting this error with my SQL code - mysql

Error says:
#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 '' at line 9
My query:
CREATE TABLE `login`.`login`(
`id` SERIAL NOT NULL,
`user` VARCHAR(20)NOT NULL,
`pass` VARCHAR(30) NOT NULL,
PRIMARY KEY(`id`),
UNIQUE(
`user`,
`pass`
)

TRY THIS
CREATE TABLE `login`(
`id` INT( 11 ) AUTO_INCREMENT NOT NULL,
`user` VARCHAR(20)NOT NULL,
`pass` VARCHAR(30) NOT NULL,
PRIMARY KEY(`id`),
UNIQUE(`user`,`pass`)
)

Related

Got a syntax error after an attempt to create tables in MySQL but all should be correct I think

I think that the syntax is correct, but when I am trying to create that tables I get syntax errors:
CREATE TABLE `authors` (
`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL
) DEFAULT CHARSET=latin1;
CREATE TABLE `categories` (
`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`img` TEXT NOT NULL
) DEFAULT CHARSET=latin1;
CREATE TABLE `reviews` (
`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`customer_id` INT(10) NOT NULL,
`product_id` INT(10) NOT NULL,
`grade` ENUM('Wspaniała', 'Dobra', 'Taka sobie', 'Zła', 'Bardzo zła') NOT NULL,
`content` TEXT NOT NULL
) DEFAULT CHARSET=latin1;
Errors:
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 `authors` (
`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMEN' at line 10
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 `categories` (
`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
' at line 10
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 `reviews` (
`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCRE' at line 1
Do You maybe know what I am doing wrong?
Thank You.
I have just got an idea to manually, table-by-table, create authors, categories, and reviews. The only things I got as bad results were warnings about INT(10) being deprecated.

#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 ')'

This is the code. However I kept getting this 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 ')' at line 7
Weirdly line 7 is the CREATE TABLE academicnews( line. Which does not contain ')' .
CREATE TABLE academicnews(
anewsID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(50) NOT NULL,
anewsContent TEXT NOT NULL,
imagePath VARCHAR(200) NOT NULL,
timeNews DATE NOT NULL,
); #Line 7
Get rid of the last comma. It is unnecessary and invalid.
CREATE TABLE academicnews(
anewsID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(50) NOT NULL,
anewsContent TEXT NOT NULL,
imagePath VARCHAR(200) NOT NULL,
timeNews DATE NOT NULL, <-- HERE
);
It should be
CREATE TABLE academicnews(
anewsID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(50) NOT NULL,
anewsContent TEXT NOT NULL,
imagePath VARCHAR(200) NOT NULL,
timeNews DATE NOT NULL
);
You are getting this error bcoz of an addition comma.
CREATE TABLE academicnews(
anewsID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(50) NOT NULL,
anewsContent TEXT NOT NULL,
imagePath VARCHAR(200) NOT NULL,
timeNews DATE NOT NULL, <--- This is the error
);
CREATE TABLE IF NOT EXISTS `testinfo` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`sl_no` int(10) NOT NULL,
`p1` int(3) DEFAULT NULL,
`p2` int(3) DEFAULT NULL,
`p3` int(3)DEFAULT select [p1]+[p2],
`mid` int(8) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `mid` (`mid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

error when creating table SQL

I'm trying to create a table in my gym_system database. Here is the code I'm using:
CREATE TABLE `Gym_System`.`login` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(30) NOT NULL,
`password` CHAR(128) NOT NULL,
) ENGINE = InnoDB;
However, I keep getting this 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 ') ENGINE = InnoDB' at line 5
Can anyone see why?
Remove the last comma
CREATE TABLE `login` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(30) NOT NULL,
`password` CHAR(128) NOT NULL
) ENGINE = InnoDB;
See fiddle demo

Why this query throwing error while inserting record

i have created one table using following query
CREATE TABLE `events` (
`event_id` bigint(20) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`event_name` varchar(100) NOT NULL,
`description` text,
`event_date` datetime NOT NULL,
`repeat` tinyint(4) NOT NULL,
`share` varchar(100) DEFAULT NULL,
`share_type` varchar(50) NOT NULL,
PRIMARY KEY (`event_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
and now i am trying to insert record using this query
INSERT INTO events (username,event_name,description,event_date,repeat,share,share_type) VALUES ('bhavik','Will go home','','2012-11-11 18:10','0','','public');
error i am getting
#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 'username,event_name,description,event_date,repeat,share,share_type) VALUES ('bha' at line 1
repeat is a reserved keyword
use `repeat` in the insert statement
INSERT INTO events (username,event_name,description,event_date,`repeat`,share,share_type) VALUES ('bhavik','Will go home','','2012-11-11 18:10','0','','public');

phpmyadmin / create table / syntax error / enum

I have searched, but frustratingly have been unable to figure out why I am getting this error on the following SQL statement.
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 ''kidney_renal_dialysis' enum('Yes','UnderTreat','No','Ref') not NULL, 'liver_c' at line 5
SQL Statement:>
CREATE TABLE `client_health_info` (
`client_id` int(11) NOT NULL PRIMARY KEY,
`ER_visits_3_months` int(2) NOT NULL,
`hospitilizations_last_year` int(2) NOT NULL,
'kidney_renal_dialysis' enum('Yes','UnderTreat','No','Ref') not NULL,
'liver_cirr_ES_liver' enum('Yes','UnderTreat','No','Ref') not NULL,
'HCAH' enum('Yes','UnderTreat','No','Ref') not NULL,
'hiv_aids' enum('Yes','UnderTreat','No','Ref') not NULL,
PRIMARY KEY (`client_id`)
) ENGINE=InnoDB not CHARSET=latin1;
You are using the wrong quotes! ;-)
CREATE TABLE `client_health_info` (
`client_id` int(11) NOT NULL PRIMARY KEY,
`ER_visits_3_months` int(2) NOT NULL,
`hospitilizations_last_year` int(2) NOT NULL,
`kidney_renal_dialysis` enum('Yes','UnderTreat','No','Ref') not NULL,
`liver_cirr_ES_liver` enum('Yes','UnderTreat','No','Ref') not NULL,
`HCAH` enum('Yes','UnderTreat','No','Ref') not NULL,
`hiv_aids` enum('Yes','UnderTreat','No','Ref') not NULL
) ENGINE=InnoDB, CHARSET=latin1;
EDIT: Fixed two further bugs: Duplicate PRIMARY KEY statement and the NOT before CHARSET.