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 ;
Related
CREATE TABLE IF NOT EXISTS `tbl_product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
`price` double(11) NOT NULL,
PRIMARY KEY (id))
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
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, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT
CHARSET=latin1 AUTO_INCRE' at line 5
try using float without the number of showing digit
CREATE TABLE IF NOT EXISTS `tbl_product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
`price` double NOT NULL,
PRIMARY KEY (id))
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
and for price could be you need a fixed decimal length so you should use decimal
CREATE TABLE IF NOT EXISTS `tbl_product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
`price` decimal(10,2) NOT NULL,
PRIMARY KEY (id))
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
You're missing a value in your double specifier:
`price` double(11) NOT NULL
It needs both the total digits and the digits following the decimal. Something like:
`price` double(11,2) NOT NULL
Though for currency values you may be better off using decimal instead:
`price` decimal(11,2) NOT NULL
As this uses a more fixed precision. Using a double may result in unexpected calculation results from how floating point arithmetic works.
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 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
The code:
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$$
Errors:
#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 '"login" (
"IdUser" int(11) NOT NULL AUTO_INCREMENT,
"username" varchar(45)' at line 1
#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 '"photos" ( "IdPhoto" int(11) NOT NULL AUTO_INCREMENT, "title" varchar(100)' at line 1
Any ideas? I'm brand new to this so any help would be very much appreciated.
Use backticks like this ` instead of double quotes throughout
For example:
`IdUser` int(11) NOT NULL AUTO_INCREMENT,
You can use double quotes in identifiers only if the ANSI_QUOTES SQL mode is enabled.
SET sql_mode='ANSI_QUOTES';
Here is SQLFiddle demo
Otherwise just use back ticks or nothing at all if your identifiers are not in a reserved words list.
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
;
Here is SQLFiddle demo
Further reading Schema Object Names
you should use backticks ` not double quotes "
like that.
CREATE TABLE `login` (
same for other columns.
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(32) NOT NULL,
`password` varchar(32) NOT NULL,
`online` int(20) NOT NULL default '0′,
`email` varchar(100) NOT NULL,
`active` int(1) NOT NULL default '0′,
`rtime` int(20) NOT NULL default '0′,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
This is the original phpmyadmin error message, when I enter the code shown above sql to create the table:
#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
'`password` varchar (32) NULL, `On-line` int NOT (20) NULL default '0 ', NON '
at line 4
I would like to understand how this code should be written correctly and what is wrong!
You should remove strange '0′ quotes for int default values. This should work for you:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(32) NOT NULL,
`password` varchar(32) NOT NULL,
`online` int(20) NOT NULL default 0,
`email` varchar(100) NOT NULL,
`active` int(1) NOT NULL default 0,
`rtime` int(20) NOT NULL default 0,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
The problem is that you are not closing you quotes correctly. You have '0′ instead of '0'.
You can either fix them of get rid of the quotes at all, since the columns are defined as integer.