MySQL query not working, probably missing a character somewhere? - mysql

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

Related

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 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;

Error 1064 - MySQL Database Creation

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 ;

Create table throws an error

Hi I am trying to create a table using SQL in Mysql but I keep getting an error.Here is my code:
USE e-commerce
CREATE TABLE `categories` (
`id` SMALLINT NOT NULL AUTO_INCREMENT,
`category` VARCHAR( 30) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `category` (`category`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
When I try to run this in phpmyadmin SQL console 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 'CREATE TABLE `categories` ( `id` SMALLINT NOT NULL AUTO_INCREMENT, `category` ' at line 2
What am I doing wrong?
Add semicolon after use
USE e-commerce;
CREATE TABLE `categories` (
`id` SMALLINT NOT NULL AUTO_INCREMENT,
`category` VARCHAR( 30) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `category` (`category`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Missing semi-colon
USE e-commerce;
CREATE TABLE `categories` (
`id` SMALLINT NOT NULL AUTO_INCREMENT,
`category` VARCHAR( 30) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `category` (`category`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
In your code you have 2 queries. You should always end query with a semicolon.
So try the following
USE e-commerce;
CREATE TABLE `categories` (
`id` SMALLINT NOT NULL AUTO_INCREMENT,
`category` VARCHAR( 30) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `category` (`category`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Syntax error when running a MySQL CREATE TABLE statement [duplicate]

This question already has answers here:
1064 error in CREATE TABLE ... TYPE=MYISAM
(5 answers)
Closed 9 years ago.
CREATE TABLE users (
user_id INT(8) NOT NULL AUTO_INCREMENT,
user_name VARCHAR(30) NOT NULL,
user_pass VARCHAR(255) NOT NULL,
user_email VARCHAR(255) NOT NULL,
user_date DATETIME NOT NULL,
user_level INT(8) NOT NULL,
UNIQUE INDEX user_name_unique (user_name),
PRIMARY KEY (user_id)
) TYPE=INNODB;
When running this query on the SQL server, I am getting 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 'TYPE=INNODB' at line 10
Any help on why this is coming up?
Instead of
TYPE=INNODB
set
Engine=InnoDB
Use ENGINE=InnoDB;
http://dev.mysql.com/doc/refman/5.0/en/using-innodb-tables.html
The manual for CREATE TABLE doesn't include TYPE; it seems to use:
ENGINE = INNODB;
And that is the default engine, so you don't really need to specify it.
Try the following query:
CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(8) NOT NULL AUTO_INCREMENT,
`user_name` varchar(30) NOT NULL,
`user_pass` varchar(255) NOT NULL,
`user_email` varchar(255) NOT NULL,
`user_date` datetime NOT NULL,
`user_level` int(8) NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `user_name_unique` (`user_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;