mysql syntax error why? - mysql

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;

Related

#1071 - Specified key was too long; max key length is 1000 bytes error in phpmyadmin

Error
SQL query:
-- --------------------------------------------------------
-- Table structure for table i18n
CREATE TABLE IF NOT EXISTS `i18n` (
`id` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`locale` VARCHAR( 6 ) NOT NULL ,
`model` VARCHAR( 255 ) NOT NULL ,
`foreign_key` INT( 10 ) NOT NULL ,
`field` VARCHAR( 255 ) NOT NULL ,
`content` TEXT,
PRIMARY KEY ( `id` ) ,
UNIQUE KEY `locale` ( `locale` , `model` , `foreign_key` , `field` ) ,
KEY `model` ( `model(50)` , `foreign_key` , `field(50)` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 AUTO_INCREMENT =1;
MySQL said: Documentation
#1071 - Specified key was too long; max key length is 1000 bytes
Replace
KEY `model` ( `model(50)` , `foreign_key` , `field(50)` )
with
KEY `model` ( `model` , `foreign_key` , `field` )
Then it works: Demo
The error you receive does not make sense for your code.
BTW do not name a column foreign_key. That is a totally undescriptive name.

Error while importing sql - Specified key was too long; max key length is 1000 bytes

I am trying to import an sql file which shows me the following error:
Error
SQL query:
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`uid` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`uemail` VARCHAR( 255 ) NOT NULL ,
`upassword` VARCHAR( 255 ) NOT NULL ,
`uname` VARCHAR( 255 ) NOT NULL ,
`uemailh` VARCHAR( 255 ) NOT NULL ,
`uclass` TINYTEXT NOT NULL ,
`regno` VARCHAR( 8 ) NOT NULL ,
`absencecount` VARCHAR( 255 ) NOT NULL DEFAULT 'a:10:{i:0;i:0;i:1;i:0;i:2;i:0;i:3;i:0;i:4;i:0;i:5;i:0;i:6;i:0;i:7;i:0;i:8;i:0;i:9;i:0;}',
`internalmarks` VARCHAR( 500 ) NOT NULL DEFAULT 's:73:"["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]";',
PRIMARY KEY ( `uid` ) ,
UNIQUE KEY `uemail` ( `uemail` , `uname` ) ,
KEY `regno` ( `regno` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 AUTO_INCREMENT =2;
MySQL said: Documentation
#1071 - Specified key was too long; max key length is 1000 bytes
I've tried to create a new database in my local machine everything works fine. But, while importing it in the remote server it shows the above error. Any Idea?

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

SQL syntax error when creating new table in MySQL

I wont to create sql tables but I receive 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 `articles_ratings` ( `ID` INT(11) NOT NULL AUTO_INCREMENT, `a' at line 10
CREATE TABLE `articles` (
`ID` int( 11 ) NOT NULL AUTO_INCREMENT ,
`a_title` varchar( 255 ) ,
`a_subtitle` tinytext,
`a_content` text,
PRIMARY KEY ( `ID` )
)
CREATE TABLE `articles_ratings` (
`ID` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`article_id` int( 11 ) NOT NULL ,
`rating_value` tinyint( 2 ) NOT NULL ,
`rater_ip` varchar( 20 ) NOT NULL ,
)
Add the primary key to your articles ratings statement or remove the last comma.
CREATE TABLE articles (
ID int( 11 ) NOT NULL AUTO_INCREMENT ,
a_title varchar( 255 ) ,
a_subtitle tinytext,
a_content text,
PRIMARY KEY ( ID )
);
CREATE TABLE articles_ratings (
ID INT( 11 ) NOT NULL AUTO_INCREMENT ,
article_id int( 11 ) NOT NULL ,
rating_value tinyint( 2 ) NOT NULL ,
rater_ip varchar( 20 ) NOT NULL ,
PRIMARY KEY ( ID )
);

Error 1064 in SQL Code

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