0

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!

3 Answers 3

4

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;
Sign up to request clarification or add additional context in comments.

1 Comment

The basic mistake. Thank You
0

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;

Comments

0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.