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

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 ;

Related

I keep getting an error when trying to make a table in phpmyadmin

when I was trying to run this code:
USE user;
CREATE TABLE IF NOT EXISTS 'posts' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'body' text NOT NULL,
'date_added' date NOT NULL,
'added_by' varchar(255) NOT NULL,
'user_posted_to' varchar(255) NOT NULL,
PRIMARY KEY ('id')
)ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;
It gave me 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 ''posts' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'body' text NOT NULL,
'dat' at line 1
how do I solve it? By the way, I already selected a database? Any help would be appreciated.
Get rid of all the "'" marks.
CREATE TABLE IF NOT EXISTS posts (
id int(11) NOT NULL AUTO_INCREMENT,
body text NOT NULL,
date_added date NOT NULL,
added_by varchar(255) NOT NULL,
user_posted_to varchar(255) NOT NULL,
PRIMARY KEY (id)
)ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;
Here is a fiddle with a working creation.

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

table creation query showing error

I am trying to create a table it is showing 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 ''duration' bigint (10) DEFAULT NULL,
'small_img' varchar(100) DEFAULT NULL' at line 6
Query is
CREATE TABLE videos_description(
`video_id` bigint(200) NOT NULL AUTO_INCREMENT,
`video_path` varchar(200) NOT NULL ,
`video_title` varchar(200) NOT NULL ,
`description` text DEFAULT NULL,
'duration' bigint (10) DEFAULT NULL,
'small_img' varchar(100) DEFAULT NULL,
'large_img' varchar(100) DEFAULT NULL,
`source_site` varchar(100) DEFAULT NULL,
`sent_by` int(20) DEFAULT NULL,
`received_by` int(20) DEFAULT NULL,
`message_id` bigint(200) DEFAULT NULL,
`visibility` varchar(30) DEFAULT NULL,
`adddate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (video_id),
FOREIGN KEY (`received_by`) REFERENCES `users` (`userid`) ON UPDATE CASCADE,
FOREIGN KEY (`sent_by`) REFERENCES `users` (`userid`) ON UPDATE CASCADE,
FOREIGN KEY (`message_id`) REFERENCES `messages` (`messageid`) ON DELETE CASCADE ON UPDATE CASCADE
)
My questions are
1) resolution of above mentioned error
2)What more fields should I include or remove for storing video details
You're using the wrong quote character on some of your column names. You should be using the backtick (`) everywhere.

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;

Mysql Create Table error on second CREATE statement [duplicate]

This question already has answers here:
node-mysql multiple statements in one query
(3 answers)
Closed 5 years ago.
I'm trying to write a script to import a Mysql DB structure. I've exported the database SQL via PhpMyAdmin, and node npm model sqldump. Both produce the same error when trying to create the second table. This doesn't seem to be table-specific - I can mix the tables around (I have 20 tables in this DB) and always hit the same error on the second CREATE TABLE statement.
Can anyone point me towards something stupid I'm missing, please?
The error is:
{ Error: 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 'CREATE TABLE IF NOT EXISTS `autoresponses` (
`id` bigint(20) NOT NULL AUTO_INC' at line 14
at PromiseConnection.query (D:\dev-mysql-update\node_modules\mysql2\promise.js:75:20)
at D:\dev-mysql-update\index.js:157:7
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
message: '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 \'CREATE TABLE IF NOT EXISTS `autoresponses` (\n `id` bigint(20) NOT NULL AUTO_INC\' at line 14',
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlState: '#42000' }
The first two tables are:
CREATE TABLE IF NOT EXISTS `autoresponders` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`uuid` char(36) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
`archived` tinyint(1) NOT NULL DEFAULT '0',
`title` varchar(255) DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
`client_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `client_id` (`client_id`),
CONSTRAINT `autoresponders_ibfk_1` FOREIGN KEY (`client_id`) REFERENCES `clients` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `autoresponses` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`uuid` char(36) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
`archived` tinyint(1) NOT NULL DEFAULT '0',
`hours_delay` int(11) DEFAULT NULL,
`status` varchar(255) DEFAULT 'active',
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
`autoresponder_id` bigint(20) DEFAULT NULL,
`notification_id` bigint(20) DEFAULT NULL,
`client_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `autoresponses_autoresponder_id_notification_id_unique` (`autoresponder_id`,`notification_id`),
KEY `notification_id` (`notification_id`),
CONSTRAINT `autoresponses_ibfk_1` FOREIGN KEY (`autoresponder_id`) REFERENCES `autoresponders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `autoresponses_ibfk_2` FOREIGN KEY (`notification_id`) REFERENCES `notifications` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Thanks in advance,
Andy
Your table name should be inside your parenthesis.