Problem with my ALTER TABLE query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeddiki
    Contributor
    • Jan 2009
    • 290

    Problem with my ALTER TABLE query

    Can anyone please tell me what is wrong with this query.

    This is my code:

    Code:
    $sql = "ALTER TABLE `cb_temp`
       ADD cb_id int(8) auto_increment, primary key (cb_id)
       ADD INDEX id (id),
       ADD INDEX start_date (start_date)";
    	
    $result = mysql_query($sql)
    	or die("could not UPDATE cb_temp". mysql_error());
    And I get this error:

    could not UPDATE cb_temp:

    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 'primary key (cb_id) ADD INDEX id (id), ADD INDEX start_date (start_date)' at line 2

    The columns that I am trying to index id and start_date already exist in the table , but cb_id does not exist, I want to create it and have it filled with consecutive numbers.

    Thanks for any help.



    .
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Use the following query.
    [code=mysql]ALTER TABLE `cb_temp` ADD cb_id int(8) auto_increment, add primary key (cb_id),
    ADD INDEX id (id),
    ADD INDEX start_date (start_date)[/code]
    You were missing ADD before primary key and a comma after (cb_id).

    Comment

    Working...