Error 1064 - MySQL Database Creation - mysql

So I'm a complete novice with MySQL and I'm trying to follow a tutorial that will allow me to sort out an Ajax + JQuery page for my database.
However, running this code in PHPMyAdmin:
CREATE TABLE IF NOT EXISTS 'add_delete_record' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'content' text NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
produces the error:
SQL query:
CREATE TABLE IF NOT EXISTS 'add_delete_record'(
'id'INT( 11 ) NOT NULL AUTO_INCREMENT , 'content'TEXT NOT NULL ,
PRIMARY KEY ( 'id' ) ) ENGINE = INNODB DEFAULT CHARSET = latin1
AUTO_INCREMENT =1 MySQL said:
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 ''add_delete_record' ( 'id' int(11) NOT NULL AUTO_INCREMENT,
'content' text' at line 1
Being a novice I have absolutely no clue what is wrong, apart from the fact that there is a problem with the syntax somewhere? Thanks to anyone who can help!

Use backticks instead. Single quotes represent string literals.
CREATE TABLE IF NOT EXISTS `add_delete_record` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`content` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

use backticks
CREATE TABLE IF NOT EXISTS `add_delete_record` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`content` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Related

MySQL ERROR 1064 in line, but don't know what is wrong?

I've got the following line I want to execute in MySQL:
CREATE TABLE 'virtual_domains' (
'id' int(11) NOT NULL auto_increment,
'name' varchar(50) NOT NULL,
PRIMARY KEY ('id'))
ENGINE=InnoDB DEFAULT CHARSET=utf8;
However, it gave me 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 ''virtual_domains' ('id' int(11) NOT NULL
auto_increment, 'name' varchar(50) NOT ' at line 1
What am I missing here??
Thanks for the help!
Rob
remove the single quotes around the table and column names. use backticks instead.
CREATE TABLE `virtual_domains` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;
In addition to use of backticks (`symbol`), since none of the identifiers you have used require escaping, you can simply remove the escaping altogether:
CREATE TABLE virtual_domains (
id int(11) NOT NULL auto_increment,
name varchar(50) NOT NULL,
PRIMARY KEY (id))
ENGINE=InnoDB DEFAULT CHARSET=utf8;
Alternatively when you do need to escape symbols, instead of using backticks, consider using ANSI compliant quotes ("symbol"). You will need to set SQL_MODE=ANSI_QUOTES:
SET SQL_MODE=ANSI_QUOTES;
CREATE TABLE "virtual_domains" (
"id" int(11) NOT NULL auto_increment,
"name" varchar(50) NOT NULL,
PRIMARY KEY ("id"))
ENGINE=InnoDB DEFAULT CHARSET=utf8;
The benefit of this is improved portability between the various RDBMS.
SqlFiddle here

MySQL query not working, probably missing a character somewhere?

I probably just missed a character somewhere but I can't seem to figure out where.
CREATE TABLE IF NOT EXISTS `paginas` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`naam` varchar NOT NULL,
`inhoud` varchar,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
The 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 'NOT NULL, inhoud varchar, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CH' at line 3
You need to specify the length for varchar fields
CREATE TABLE IF NOT EXISTS `paginas` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`naam` varchar(255) NOT NULL,
`inhoud` varchar(255),
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
See fiddle demo

Creating tables in PhpMyAdmin - error 1064

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.

Mysql throws an error when one table name is not surrounded by single quotes

I'm building a simple app which lists teams and matches. The Team and Match databases were built with the following scripts (I'm using PhpMyadmin):
CREATE TABLE IF NOT EXISTS `Team` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(120) NOT NULL,
`screen_name` varchar(100) NOT NULL,
`sport_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `Match` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sport_id` int(11) NOT NULL,
`team_one_id` int(11) NOT NULL,
`team_two_id` int(11) NOT NULL,
`venue` varchar(80) NOT NULL,
`kick_off` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
If i do:
SELECT * FROM Team
The script runs and I get an empty result. But, incredibly, if I do
SELECT * FROM Match
I get the following 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 'Match' at line 1
Instead, I have to do:
SELECT * FROM `Match`
And it works. I have other tables in the database but this is the only behaving like this. Any ideas why?
match is a reserved word in SQL
Read more here:
https://drupal.org/node/141051
Match is a Function in MySQL therefore you must put the quotes around it.
You need encapsulate it in quotes because Match is a keyword.
See key word list

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;