error when creating table SQL - mysql

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

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.

MySql table doesn't create when I try to add "AUTO_INCREMENT"

CREATE TABLE `userinfo`.`users`
( id MEDIUMINT NOT NULL AUTO_INCREMENT ,
`username` VARCHAR NOT NULL ,
`password` VARCHAR NOT NULL ,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
Could anyone give me an insight as to why this create table function isn't working? Error code:
#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 'NOT NULL ,
password VARCHAR NOT NULL ,
PRIMARY KEY (id))
ENGINE ...' at line 3
new to mysql so i have no clue what the problem is. I just want a table that has the primary key increment when i add to it. Thanks in advance.
CREATE TABLE `userinfo`.`users`
( id MEDIUMINT NOT NULL AUTO_INCREMENT ,
`username` VARCHAR(50) NOT NULL ,
`password` VARCHAR(50) NOT NULL ,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
You need to specify maximum character limit for VARCHAR type as above. You can set it as per your requirement.

Sql syntax error on DROP TABLE

I am trying to create a MySQL table with the following code:
CREATE DATABASE
IF NOT EXISTS myusers;USE
DROP TABLE
DROP TABLE IF EXISTS `myusers`.`users`;CREATE TABLE `myusers`.`users`
(
`username` VARCHAR(45) NOT NULL,
`password` VARCHAR(45) NULL,
`firstname` VARCHAR(45) NOT NULL,
`lastname` VARCHAR(45) NULL,
`phone` INT NULL,
PRIMARY KEY (`username`)
)
However, 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 'DROP TABLE
DROP TABLE IF EXISTS myusers.users' at line 2
I have limited knowledge of MySQL. From what I know about SQL syntax this looks fine.
Any idea what could be the issue here?
USE should be followed by a database name.
There is extra DROP Table.
Drop the table if exists DROP TABLE IF EXISTS users first.
Then create the table.
Like this:
CREATE DATABASE IF NOT EXISTS myusers;
USE myusers;
DROP TABLE IF EXISTS `users`;
CREATE TABLE `myusers`.`users`
(
`username` VARCHAR(45) NOT NULL,
`password` VARCHAR(45) NULL,
`firstname` VARCHAR(45) NOT NULL,
`lastname` VARCHAR(45) NULL,
`phone` INT NULL,
PRIMARY KEY (`username`)
);

Continually getting this error with my SQL code

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

ERROR 1064 (42000): You have an error in your SQL syntax;

I have a MySQL commands:
CREATE DATABASE IF NOT EXISTS courses;
USE courses
CREATE TABLE IF NOT EXISTS teachers(
id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
name VAR_CHAR(50) NOT NULL,
addr VAR_CHAR(255) NOT NULL,
phone INT NOT NULL,
);
When I run it, I get an 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 'VAR_CHAR(50) NOT NULL, addr VAR_CHAR(255) NOT
NULL, phone INT NOT NULL, )' at line 3
It is varchar and not var_char
CREATE DATABASE IF NOT EXISTS courses;
USE courses;
CREATE TABLE IF NOT EXISTS teachers(
id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
addr VARCHAR(255) NOT NULL,
phone INT NOT NULL
);
You should use a SQL tool to visualize possbile errors like MySQL Workbench.
Try this:
Use back-ticks for NAME
CREATE TABLE `teachers` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`addr` varchar(255) NOT NULL,
`phone` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Use varchar instead of VAR_CHAR and omit the comma in the last line i.e.phone INT NOT NULL
);. The last line during creating table is kept "comma free".
Ex:- CREATE TABLE COMPUTER
(
Model varchar(50)
);
Here, since we have only one column ,that's why there is no comma used during entire code.