Error 1064 in SQL Code - mysql

I used the phpMyAdmin form to create a table, i.e. I filled in the fields and it generated the code. The code generated doesn't work, but I can't find the error. Any help would be appreciated.
#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 '( 1 ) NOT NULL DEFAULT '0',
userEmail VARCHAR( 255 ) NOT NULL ,PRIMARY KEY (' at line 14
Here's the code:
CREATE TABLE members (
userID INT( 9 ) NOT NULL AUTO_INCREMENT ,
userName VARCHAR( 15 ) NOT NULL ,
userPwd VARCHAR( 16 ) NOT NULL ,
userTitle VARCHAR( 4 ) NOT NULL ,
fName VARCHAR( 30 ) NOT NULL ,
lName VARCHAR( 30 ) NOT NULL ,
address VARCHAR( 255 ) NULL ,
dateOfBirth VARCHAR( 10 ) NULL ,
userJob VARCHAR( 15 ) NULL ,
regDate VARCHAR( 20 ) NOT NULL ,
accType CHAR( 1 ) NOT NULL DEFAULT 'F',
regCode VARCHAR( 255 ) NOT NULL ,
isActivated BOOL( 1 ) NOT NULL DEFAULT '0',
userEmail VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( userID ) ,
UNIQUE (userName ,userEmail)
) ENGINE = MYISAM
mysql ver 5.1 php ver 5.2.*

You cannot use BOOL(1)
Try the following (i just replaced BOOL(1) with BOOL)
BOOL and BOOLEAN are synonyms for TINYINT(1).
CREATE TABLE members (
userID INT( 9 ) NOT NULL AUTO_INCREMENT ,
userName VARCHAR( 15 ) NOT NULL ,
userPwd VARCHAR( 16 ) NOT NULL ,
userTitle VARCHAR( 4 ) NOT NULL ,
fName VARCHAR( 30 ) NOT NULL ,
lName VARCHAR( 30 ) NOT NULL ,
address VARCHAR( 255 ) NULL ,
dateOfBirth VARCHAR( 10 ) NULL ,
userJob VARCHAR( 15 ) NULL ,
regDate VARCHAR( 20 ) NOT NULL ,
accType CHAR( 1 ) NOT NULL DEFAULT 'F',
regCode VARCHAR( 255 ) NOT NULL ,
isActivated BOOL NOT NULL DEFAULT '0',
userEmail VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( userID ) ,
UNIQUE (userName ,userEmail)
) ENGINE = MYISAM

Change
isActivated BOOL( 1 ) NOT NULL DEFAULT '0',
to
isActivated BOOL NOT NULL DEFAULT '0',
you can read about it more : here
M indicates the maximum display width for integer types
Bool does not have this so you can't specify width. it's always 1

Related

mysql syntax error why?

mysql query
CREATE TABLE IF NOT EXISTS 'sadakin'.'gcm_users' (
'id' int( 11 ) NOT NULL AUTO_INCREMENT ,
'gcm_regid' text,
'name' varchar( 50 ) NOT NULL ,
'email' varchar( 255 ) NOT NULL ,
'imei' varchar( 20 ) NOT NULL ,
'created_at' timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( 'id' ) ,
KEY 'imei' ( 'imei' )
) ENGINE = InnoDB DEFAULT CHARSET = latin1 AUTO_INCREMENT =1;
Error message:
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 ''sadakin'.'gcm_users' (
'id' int( 11 ) NOT NULL AUTO_INCREMENT ,
'gcm_' at line 1
I don't find error. Help me!
Use backticks to enclose identifiers. Quotes are just for strings:
CREATE TABLE IF NOT EXISTS `sadakin`.`gcm_users` (
`id` int( 11 ) NOT NULL AUTO_INCREMENT ,
`gcm_regid` text,
`name` varchar( 50 ) NOT NULL ,
`email` varchar( 255 ) NOT NULL ,
`imei` varchar( 20 ) NOT NULL ,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( `id` ) ,
KEY `imei` ( `imei` )
) ENGINE = InnoDB DEFAULT CHARSET = latin1 AUTO_INCREMENT =1;
There is no need of any single quotes on column names
CREATE TABLE IF NOT EXISTS sadakin.gcm_users (
id int( 11 ) NOT NULL AUTO_INCREMENT ,
gcm_regid text,
name varchar( 50 ) NOT NULL ,
email varchar( 255 ) NOT NULL ,
imei varchar( 20 ) NOT NULL ,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( id ) ,
KEY imei ( imei )
) ENGINE = InnoDB DEFAULT CHARSET = latin1 AUTO_INCREMENT =1;
You have to use back-ticks instead of single quotes. Quotes are used for string literals.
Check this: http://dev.mysql.com/doc/refman/5.0/en/string-literals.html
A string is a sequence of bytes or characters, enclosed within either
single quote (“'”) or double quote (“"”)
Try:
CREATE TABLE IF NOT EXISTS `sadakin`.`gcm_users` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`gcm_regid` TEXT,
`name` VARCHAR( 50 ) NOT NULL ,
`email` VARCHAR( 255 ) NOT NULL ,
`imei` VARCHAR( 20 ) NOT NULL ,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( `id` ) ,
KEY `imei` ( `imei` )
) ENGINE = INNODB DEFAULT CHARSET = latin1 AUTO_INCREMENT =1;

Syntax error in create table query

I cant get this syntax 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 '(id) ENGINE=MyISAM)' at line 15
CREATE TABLE IF NOT EXISTS `destination_cdr` (
`id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT ,
`calldate` DATETIME NOT NULL ,
`source` VARCHAR( 80 ) NOT NULL ,
`destination` VARCHAR( 80 ) NOT NULL ,
`account_code` VARCHAR( 30 ) DEFAULT NULL ,
`pincode` VARCHAR( 45 ) NOT NULL ,
`duration_call` BIGINT( 20 ) NOT NULL DEFAULT '0',
`duration_talk` BIGINT( 20 ) NOT NULL ,
`disposition` VARCHAR( 255 ) NOT NULL ,
`clid` VARCHAR( 80 ) DEFAULT NULL ,
`cdr_id` BIGINT( 20 ) DEFAULT NULL ,
`vxcdr_id` BIGINT( 20 ) DEFAULT NULL ,
`provider` INT( 11 ) NOT NULL DEFAULT '0' PRIMARY KEY ( `id` )) ENGINE = MYISAM
;
You need a commma between provider and primary Key:
`provider` INT( 11 ) NOT NULL DEFAULT '0', PRIMARY KEY ( `id` )) ENGINE = MYISAM
Missing comma before primary key clause.
`provider` INT( 11 ) NOT NULL DEFAULT '0', PRIMARY KEY ( `id` ))
Error
SQL query:
--
-- Database: wadud
--
-- Table structure for table destination
CREATE TABLE destination (
id bigint(20) NOT NULL,
country varchar(255) NOT NULL,
photo text NOT NULL,
tours varchar(255) NOT NULL,
created_at timestamp NULL DEFAULT NULL,
updated_at timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
MySQL said: Documentation
1050 - Table 'destination' already exists

#1067 - Invalid default value for 'membership'

I am using a SQL file included in my program and once I fixed an issue that I was able to find the answer to in here (THANK YOU).. I ran it again and got the following error:
SQL query:
# Create table structure for 'member' table
CREATE TABLE member(
memberID INT( 11 ) NOT NULL AUTO_INCREMENT ,
title VARCHAR( 80 ) NOT NULL DEFAULT '',
firstname VARCHAR( 80 ) NOT NULL DEFAULT '',
lastname VARCHAR( 80 ) NOT NULL DEFAULT '',
email VARCHAR( 80 ) NOT NULL DEFAULT '',
address VARCHAR( 80 ) NOT NULL DEFAULT '',
suburb VARCHAR( 80 ) NOT NULL DEFAULT '',
state VARCHAR( 80 ) NOT NULL DEFAULT '',
country VARCHAR( 80 ) NOT NULL DEFAULT '',
postcode VARCHAR( 11 ) NOT NULL DEFAULT '',
mobile VARCHAR( 80 ) NOT NULL DEFAULT '',
phone VARCHAR( 80 ) NOT NULL DEFAULT '',
fax VARCHAR( 80 ) NOT NULL DEFAULT '',
membership INT( 2 ) NOT NULL DEFAULT '',
payment INT( 2 ) NOT NULL DEFAULT '',
startdate BIGINT( 14 ) NOT NULL DEFAULT 0,
enddate BIGINT( 14 ) NOT NULL DEFAULT 0,
userID INT( 11 ) NOT NULL ,
PRIMARY KEY ( memberID ) ,
UNIQUE (
memberID
)
) ENGINE = MYISAM ;
MySQL said:
#1067 - Invalid default value for 'membership'
What do I need to change to make this work ? this is an older script, but I am not knowledgeable enough to know what needs to be changed for MySQL 5.5 version.
Thank you so much for your help!
And I'm sure there will be other errors popping up after I fix this one..
The membership column is an int, but you're giving it a default string value of ''. So change
membership INT( 2 ) NOT NULL DEFAULT '',
to
membership INT( 2 ) NOT NULL DEFAULT 0,
(0 or whatever default value you want for that field.)
I was getting:
Incorrect integer value: '' for column 'column_name' at row 1
I've fixed it editing /etc/mysql/my.cnf or /etc/mysql/mysql.conf.d/mysqld.cnf files. Then find the following line:
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
and replace it for
sql-mode=""
and restart MySQL: service mysql restart

mysql 1064 error ou have an error in your SQL syntax;

creating a table in phpmyadmin it shows following error![enter image description here][1]
Error
SQL query:
CREATE TABLE `user` (
`usrID` BIGINT( 11 ) NOT NULL ,
`name` VARCHAR( 100 ) NOT NULL ,
`email` VARCHAR( 100 ) NOT NULL ,
`mobile` VARCHAR( 10 ) NOT NULL ,
`gender` CHAR( 10 ) NOT NULL ,
`countryID` INT( 11 ) NULL ,
`stateID` INT( 11 ) NULL ,
`cityID` INT( 11 ) NULL ,
`pincode` VARCHAR( 6 ) NULL ,
`place` VARCHAR( 100 ) NULL ,
`address` VARCHAR( 200 ) NULL ,
`usertype` VARCHAR( 5 ) NULL ,
`pass` VARCHAR( 20 ) NULL ,
`edate` DATETIME NULL ,
`eusrID` INT( 11 ) NULL ,
`busrID` INT( 11 ) NULL ,
`adminID` INT( 11 ) NULL ,
`active` SET( 1 ) NOT NULL
) ENGINE = innodb
MySQL said: Documentation
#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 '1) NOT NULL) ENGINE = innodb' at line 1
The value of 1 should be wrap with single quote. See here for details.
`active` SET( '1' ) NOT NULL
SQLFiddle Demo
SET takes a number of possible string values for the column, for example;
`color` SET('red', 'green', 'blue')
This would mean that the column could have the values 'red', 'red,blue', 'red,green,blue' etc.
Your definition;
`active` SET(1)
doesn't really make any sense. Either you're looking for a boolean flag (INT(1)) or you need to list the possible values the field can have. Note that SET('yes','no') would allow all of the values 'yes', 'no' and 'yes,no' (the combination), which may not be the best choice for an active flag.

#1064 - You have an error in your SQL syntax; [duplicate]

This question already has answers here:
1064 error in CREATE TABLE ... TYPE=MYISAM
(5 answers)
Closed 9 years ago.
I am getting the following error whenever I want to create a table in MySQL.
#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 '( 32 ) NOT NULL DEFAULT CURRENT_TIMESTAMP , `visitor_day` SMALLINT( 2 ) NOT NUL' at line 7
code:
CREATE TABLE `visitors_table` (
`ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`visitor_ip` VARCHAR( 32 ) NULL ,
`visitor_browser` VARCHAR( 255 ) NULL ,
`visitor_hour` SMALLINT( 2 ) NOT NULL DEFAULT '00',
`visitor_minute` SMALLINT( 2 ) NOT NULL DEFAULT '00',
`visitor_date` TIMESTAMP( 32 ) NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`visitor_day` SMALLINT( 2 ) NOT NULL ,
`visitor_month` SMALLINT( 2 ) NOT NULL ,
`visitor_year` SMALLINT( 4 ) NOT NULL ,
`visitor_refferer` VARCHAR( 255 ) NULL ,
`visitor_page` VARCHAR( 255 ) NULL
) TYPE = MYISAM ;
Couple of errors fixed here:
CREATE TABLE `visitors_table` (
`ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`visitor_ip` VARCHAR( 32 ) NULL ,
`visitor_browser` VARCHAR( 255 ) NULL ,
`visitor_hour` SMALLINT( 2 ) NOT NULL DEFAULT '00',
`visitor_minute` SMALLINT( 2 ) NOT NULL DEFAULT '00',
`visitor_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`visitor_day` SMALLINT( 2 ) NOT NULL ,
`visitor_month` SMALLINT( 2 ) NOT NULL ,
`visitor_year` SMALLINT( 4 ) NOT NULL ,
`visitor_refferer` VARCHAR( 255 ) NULL ,
`visitor_page` VARCHAR( 255 ) NULL
) ENGINE = MYISAM ;
TIMESTAMP does not support precision. Not until MySQL 5.6, that is, where sub-second resolution is possible.
Remove the ( 32 ) from the TIMESTAMP definition.
TIMESTAMP does not have a size and you should use engine instead of type
CREATE TABLE `visitors_table` (
`ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`visitor_ip` VARCHAR( 32 ) NULL ,
`visitor_browser` VARCHAR( 255 ) NULL ,
`visitor_hour` SMALLINT( 2 ) NOT NULL DEFAULT '00',
`visitor_minute` SMALLINT( 2 ) NOT NULL DEFAULT '00',
`visitor_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`visitor_day` SMALLINT( 2 ) NOT NULL ,
`visitor_month` SMALLINT( 2 ) NOT NULL ,
`visitor_year` SMALLINT( 4 ) NOT NULL ,
`visitor_refferer` VARCHAR( 255 ) NULL ,
`visitor_page` VARCHAR( 255 ) NULL
) engine = MYISAM ;