I do not undertstand what is the problem with this:
CREATE TABLE 'posts' (
'IdPost' int(11) NOT NULL AUTO_INCREMENT,
'IdUser' int(11) NOT NULL,
'name' varchar(45) CHARACTER SET latin1 NOT NULL,
'title' varchar(100) CHARACTER SET latin1 NOT NULL,
'type' tinyint(4) NOT NULL,
'address' varchar(30) CHARACTER SET latin1 NOT NULL,
'lat' varchar(10) NOT NULL,
'lon' varchar(10) NOT NULL,
'url' varchar(30) NOT NULL,
PRIMARY KEY ('IdPost')
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
I am getting this error on my server:
#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 ''posts' ( 'IdPost' int(11) NOT NULL AUTO_INCREMENT, 'IdUser' int(11) NOT NUL' at line 1
What is the problem?
Do not use the quotes for your table name. Also remove all the quotes from your column name too.
DEMO SQL FIDDLE
On a side note:-
From here:-
Quoting is useful when an identifier is an SQL reserved word or
contains spaces or other special characters. Quoting an identifier
also enables it to be entirely numeric, something not true of unquoted
identifiers. To include an identifier quote character within a quoted
identifier, double it.
Don't put your table or column names in quotes. You have to use backticks for reserved words which is not the case for this table.
CREATE TABLE posts
(
IdPost int(11) NOT NULL AUTO_INCREMENT,
IdUser int(11) NOT NULL,
name varchar(45) CHARACTER SET latin1 NOT NULL,
title varchar(100) CHARACTER SET latin1 NOT NULL,
type tinyint(4) NOT NULL,
address varchar(30) CHARACTER SET latin1 NOT NULL,
lat varchar(10) NOT NULL,
lon varchar(10) NOT NULL,
url varchar(30) NOT NULL,
PRIMARY KEY (IdPost)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
This can be an alternative:
CREATE TABLE `posts` (
`IdPost` int(11) NOT NULL AUTO_INCREMENT,
`IdUser` int(11) NOT NULL,
`name` varchar(45) CHARACTER SET latin1 NOT NULL,
`title` varchar(100) CHARACTER SET latin1 NOT NULL,
`type` tinyint(4) NOT NULL,
`address` varchar(30) CHARACTER SET latin1 NOT NULL,
`lat` varchar(10) NOT NULL,
`lon` varchar(10) NOT NULL,
`url` varchar(30) NOT NULL,
PRIMARY KEY (`IdPost`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
I would suggest to use back tilts instead of quotes
Related
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 6 months ago.
#here is my query
CREATE TABLE IF NOT EXISTS 'details' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'name' varchar(200) NOT NULL,
'email' varchar(200) NOT NULL,
'gender' varchar(200) NOT NULL,
'address' longtext NOT NULL,
'username' varchar(30) NOT NULL,
'password' varchar(30) NOT NULL,
'verify' tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
Replace names of columns with back ticks.
String use normal single quotes chars.
So:
CREATE TABLE IF NOT EXISTS `details` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
`email` varchar(200) NOT NULL,
`gender` varchar(200) NOT NULL,
`address` longtext NOT NULL,
`username` varchar(30) NOT NULL,
`password` varchar(30) NOT NULL,
`verify` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
I'm struggling to code this table as it's giving me a #1064 error, and this corresponds to a few potential issues. If someone could point out where I've made a mistake that would be great.
Here is an image of the code I've typed, and the error I've received:
The code:
CREATE TABLE `RENRMyLUoX`.`movie`(
`mID` INT(20) NOT NULL,
`title` VARCHAR(50) NULL DEFAULT NULL,
`relYear` YEAR(4) NULL DEFAULT NULL,
`category` VARCHAR(50) NULL DEFAULT NULL,
`runTime` INT(20) NOT NULL,
`studioName` VARCHAR(50) NULL DEFAULT NULL,
`description` VARCHAR(50) NULL DEFAULT NULL,
`rating` DOUBLE(20) NULL DEFAULT NULL,
PRIMARY KEY(`mID`(20))
) ENGINE = InnoDB CHARSET = latin1 COLLATE latin1_bin;
The DOUBLE datatype should be specified as either DOUBLE or DOUBLE(m, d). I don't understand what (20) is supposed to do... you can simply omit it:
rating DOUBLE NULL DEFAULT NULL,
TRY BELOW CODE
CREATE TABLE RENRMyLUoX.movie(
mID INT(20) NOT NULL,
title VARCHAR(50) NULL DEFAULT NULL,
relYear YEAR(4) NULL DEFAULT NULL,
category VARCHAR(50) NULL DEFAULT NULL,
runTime INT(20) NOT NULL,
studioName VARCHAR(50) NULL DEFAULT NULL,
description VARCHAR(50) NULL DEFAULT NULL,
rating DOUBLE(20) NULL DEFAULT NULL)ENGINE = InnoDB CHARSET = latin1 COLLATE latin1_bin;
ALTER TABLE RENRMyLUoX.movie
ADD PRIMARY KEY (mID)
ALTER TABLE RENRMyLUoX.movie
MODIFY mID int(20) NOT NULL AUTO_INCREMENT;
COMMIT;
I am trying to use MySQL Workbench 8.0.3 with MariaDB but I get the following error:
Executing:
CREATE TABLE `mydb`.`customer` (
`ID` INT UNIQUE UNSIGNED NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) NOT NULL,
`Email` VARCHAR(255) CHARACTER SET 'utf8' NOT NULL,
`Street` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_czech_ci' NOT NULL,
`City` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_czech_ci' NOT NULL,
PRIMARY KEY (`ID`));
ERROR 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 'UNSIGNED NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) NOT NULL,
`Email` VARC' at line 2
SQL Statement:
CREATE TABLE `mydb`.`customer` (
`ID` INT UNIQUE UNSIGNED NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) NOT NULL,
`Email` VARCHAR(255) CHARACTER SET 'utf8' NOT NULL,
`Street` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_czech_ci' NOT NULL,
`City` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_czech_ci' NOT NULL,
PRIMARY KEY (`ID`))
Operation failed: There was an error while applying the SQL script to the database.
The code you see above has been generated using the "Create Table" Workbench feature.
UNSIGNED and INT go together, so this works:
`ID` INT UNSIGNED UNIQUE NOT NULL AUTO_INCREMENT,
This is shorter:
`ID` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
A primary key is already non-NULL and unique. There is no need to declare those properties twice.
I solved it by using int(10) instead of int
ID INT(10)
not
ID INT
How would one format the following sql file in a way that would work and keep the current values;
delimiter $$
CREATE TABLE "login" (
"IdUser" int(11) NOT NULL AUTO_INCREMENT,
"username" varchar(45) CHARACTER SET latin1 NOT NULL,
"pass" varchar(45) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY ("IdUser")
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$
CREATE TABLE "photos" (
"IdPhoto" int(11) NOT NULL AUTO_INCREMENT,
"title" varchar(100) CHARACTER SET latin1 NOT NULL,
"IdUser" int(11) NOT NULL,
PRIMARY KEY ("IdPhoto")
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8$$
I get the following error when I try to create it from my mac terminal
"'ERROR 1064 (42000) at line 3: 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 '"login" (
"IdUser" int(11) NOT NULL AUTO_INCREMENT,
"username" varchar(45) C' at line 1
"
use this. Fiddler Demo
CREATE TABLE login (
IdUser int(11) NOT NULL AUTO_INCREMENT,
username varchar(45) CHARACTER SET latin1 NOT NULL,
pass varchar(45) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (IdUser)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE photos (
IdPhoto int(11) NOT NULL AUTO_INCREMENT,
title varchar(100) CHARACTER SET latin1 NOT NULL,
IdUser int(11) NOT NULL,
PRIMARY KEY (IdPhoto)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
CREATE TABLE login (//"login" is incorrect syntex
IdUser int(11) NOT NULL AUTO_INCREMENT, // Dont give "" to Column name
username varchar(45) CHARACTER SET latin1 NOT NULL,
pass varchar(45) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (IdUser)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$
CREATE TABLE photos (//"photos" is incorrect syntex
IdPhoto int(11) NOT NULL AUTO_INCREMENT,
title varchar(100) CHARACTER SET latin1 NOT NULL,
IdUser int(11) NOT NULL,
PRIMARY KEY (IdPhoto)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFA
I am trying to run the following query in PHP my admin:
CREATE TABLE IF NOT EXISTS 'ibn_table' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'itransaction_id' varchar(60) NOT NULL,
'ipayerid' varchar(60) NOT NULL,
'iname' varchar(60) NOT NULL,
'iemail' varchar(60) NOT NULL,
'itransaction_date' datetime NOT NULL,
'ipaymentstatus' varchar(60) NOT NULL,
'ieverything_else' text NOT NULL,
PRIMARY KEY ('id')
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
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 ''ibn_table' ( 'id' int(11) NOT NULL AUTO_INCREMENT, 'itransaction_id' varchar(' at line 1
Any help is appreciated.
use backtick for quoting columns and table names
mysql> CREATE TABLE IF NOT EXISTS `ibn_table` (
-> `id` int(11) NOT NULL AUTO_INCREMENT,
-> `itransaction_id` varchar(60) NOT NULL,
-> `ipayerid` varchar(60) NOT NULL,
-> `iname` varchar(60) NOT NULL,
-> `iemail` varchar(60) NOT NULL,
-> `itransaction_date` datetime NOT NULL,
-> `ipaymentstatus` varchar(60) NOT NULL,
-> `ieverything_else` text NOT NULL,
-> PRIMARY KEY (`id`)
-> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Query OK, 0 rows affected (0.12 sec)
The column names should be in Backticks or just remove quotes. Backticks are to be used for table and column identifiers, but are only necessary when the identifier is a MySQL reserved keyword, or when the identifier contains whitespace characters or characters beyond a limited set (see below) It is often recommended to avoid using reserved keywords as column or table identifiers when possible, avoiding the quoting issue.
Try this:
CREATE TABLE `ibn_table` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`itransaction_id` VARCHAR(60) NOT NULL,
`ipayerid` VARCHAR(60) NOT NULL,
`iname` VARCHAR(60) NOT NULL,
`iemail` VARCHAR(60) NOT NULL,
`itransaction_date` DATETIME NOT NULL,
`ipaymentstatus` VARCHAR(60) NOT NULL,
`ieverything_else` TEXT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;