Creating tables in PhpMyAdmin - error 1064 - mysql

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.

Related

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB

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.

ALTER TABLE table_name AUTO_INCREMENT = 1000; gives me syntax error

this is my table export:
CREATE TABLE IF NOT EXISTS `order` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`comment` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`shipping_cost` double DEFAULT NULL,
`customer_id` int(11) NOT NULL,
`delivery_type` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`invoice_nr` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`deleted_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `order_customer_id_index` (`customer_id`),
KEY `order_invoice_nr_index` (`invoice_nr`),
KEY `order_created_at_index` (`created_at`),
KEY `order_updated_at_index` (`updated_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
when I run now:
ALTER TABLE order AUTO_INCREMENT=1000;
I get:
#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 'order AUTO_INCREMENT=1000' at line 1
the table is empty!
mysql version: 5.5.44-0ubuntu0.14.04.1
someone has an idea what could cause me this problem?
if I put for example this:
ALTER TABLE asdasdfasdfasdf AUTO_INCREMENT=1000;
I get
1146 - Table 'mydb.asdasdfasdfasdf' doesn't exist
Try:
ALTER TABLE `order` AUTO_INCREMENT=1000;
Order is a reserved word, it's trying to order...

Sql creation format

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

Creating table mySQL syntax error

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 ;

MYSQL Table Error - 1064

Trying to create the following table:
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$$);
Doesn't seem to work properly. The error I'm getting in MYSQL is:
#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 '=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$' at line 6
Bracket in the wrong spot:
PRIMARY KEY (IdUser),
ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$);
^----
should be
PRIMARY KEY (IdUser) <--note removed comma
) ENGINE=MyIsam etc...
^---
You're treating those table options as they were fields, by placing them WITHIN the () field definition block.
In my case some of the sql is working but mostly not working after changing Type=ENGINE.
CREATE TABLE `p4_acl_page` (
`id` int(2) NOT NULL auto_increment,
`label` varchar(80) default NULL,
`lastupdate` timestamp(14) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyIsam;