Unknown CREATE TABLE syntax error near 'unsigned int ..' - mysql

I've been staring at this simple CREATE TABLE query for 20 minutes, and I can't figure out why it's throwing an error:
create table `schema_change` (
`schema_change_id` unsigned int not null auto_increment,
`major_release_number` unsigned int not null,
`minor_release_number` unsigned int not null,
`point_release_number` unsigned int not null,
`script_name` varchar(100) not null,
`date_applied` datetime not null,
constraint `pk_schema_change` primary key (
`schema_change_id`
)
);
The error returned is a basic syntax error, but I can't spot any syntax that's incorrect:
#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 'unsigned int not null, minor_release_number unsigned int not
null, point_rel' at line 3
What am I missing?
(Using MySQL version 5.1.73)

UNSIGNED is a type attribute, and must come after the type name: INT UNSIGNED, not UNSIGNED INT.

You must use unsigned after the type, as it modifies the type of int
create table `schema_change` (
`schema_change_id` int unsigned auto_increment,
`major_release_number` int unsigned not null,
`minor_release_number` int unsigned not null,
`point_release_number` int unsigned not null,
`script_name` varchar(100) not null,
`date_applied` datetime not null,
constraint `pk_schema_change` primary key (
`schema_change_id`
)
);
See in action here: http://sqlfiddle.com/#!9/685bf/1

Related

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

I am using Sequel Pro with MySQL on my Mac. I return the error: "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 ')' " every time I attempt to run this sql query. The Database is created successfully, but the table is not. Can anyone advise where the error in my syntax is? I simply do not see it:
CREATE DATABASE bamazon
USE bamazon;
CREATE TABLE products
(
`id` int NOT NULL AUTO_INCREMENT,
`product_name` varchar(45) NOT NULL,
`department_name` varchar(45) NOT NULL,
`price` int NOT NULL,
`stock_quantity` int NOT NULL,
PRIMARY KEY (id),
);
Please remove the ',' after PRIMARY KEY (id). It should be like this
CREATE TABLE products
(
id int NOT NULL AUTO_INCREMENT,
product_name varchar(45) NOT NULL,
department_name varchar(45) NOT NULL,
price int NOT NULL,
stock_quantity int NOT NULL,
PRIMARY KEY (id)
);
The query does not work because there is an extra comma (,) at the end. Remove that and it will work. The correct syntax will be:
CREATE TABLE products
(
id int NOT NULL AUTO_INCREMENT,
product_name varchar(45) NOT NULL,
department_name varchar(45) NOT NULL,
price int NOT NULL,
stock_quantity int NOT NULL,
PRIMARY KEY (id)
);

Mysql creating table error integer

With this code:
create table jogadores(
id INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
nome varchar NOT NULL,
idade int NOT NULL UNSIGNED,
nacionalidade varchar NOT NULL
)
I keep getting this error:
)
Error report -
SQL Error: 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,
idade int NOT NULL UNSIGNED,
nacionalidade varchar NOT NULL
)' at line 3.
Also, I get the red underline under the "T" and the "(" in "INT(10)".
varchar() should have a length:
create table jogadores (
id INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
nome varchar(255) NOT NULL,
idade int UNSIGNED NOT NULL,
nacionalidade varchar(255) NOT NULL
);
And UNSIGNED needs to go immediately after the numeric declaration, not after NOT NULL. See here.
You need to specify the length of the varchar i.e. varchar(100).

Having Trouble with MySQL Primary Key and adding Index (Error #1064)

CREATE TABLE registers(
User_ID INT UNSIGNED NOT NULL PRIMARY KEY,
IP INT UNSIGNED NOT NULL INDEX,
Success TINYINT UNSIGNED NOT NULL,
Time_Created DATETIME NOT NULL)
I get 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 'INDEX,
Success TINYINT UNSIGNED NOT NULL,
Time_Created DATETIME NOT NULL)' at line 3
To define inline indexes in a CREATE TABLE statement, you will need to place it on a separate 'create definition' line:
CREATE TABLE registers(
User_ID INT UNSIGNED NOT NULL PRIMARY KEY,
IP INT UNSIGNED NOT NULL,
INDEX(IP),
Success TINYINT UNSIGNED NOT NULL,
Time_Created DATETIME NOT NULL
);
SqlFiddle
You can also place the index definition outside of the table definition, like so:
CREATE INDEX IX_registers_ip ON registers(IP);
It is regarded as good practice to name the index, so that it can be referenced exactly.
Your synatx must be:
CREATE TABLE registers(
User_ID INT UNSIGNED NOT NULL PRIMARY KEY,
IP INT UNSIGNED NOT NULL ,
Success TINYINT UNSIGNED NOT NULL,
Time_Created DATETIME NOT NULL,
INDEX (IP )
)
For more information about the create table statement see the official mysql documentation
Try this instead - in MySQL syntax the INDEX definition cannot be included in the field definition:
CREATE TABLE registers(
User_ID INT UNSIGNED NOT NULL PRIMARY KEY,
IP INT UNSIGNED NOT NULL,
Success TINYINT UNSIGNED NOT NULL,
Time_Created DATETIME NOT NULL,
INDEX `ip_1` (`ip`)
)
Alternatively - sometimes preferred for readability you can create the index in a separate statement after you create the table:
CREATE TABLE registers(
User_ID INT UNSIGNED NOT NULL PRIMARY KEY,
IP INT UNSIGNED NOT NULL,
Success TINYINT UNSIGNED NOT NULL,
Time_Created DATETIME NOT NULL
);
CREATE INDEX ip_1 ON registers (ip);

#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 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.