MySQL Alter Table Help

Discussion in 'MySQL' started by Darkhodge, Mar 19, 2006.

  1. #1
    Hi,


    Sorry I'm a complete beginner when it comes to MySQL... Anyway I'm trying to add something to a table that exists called 'dk_users' using PHPMySQL. The guide told me to add the following to this table:

    `petid` smallint(5) unsigned NOT NULL default '0',

    So to do that what do I do? After about 30 minutes of research my guess was that it's:

    ALTER TABLE 'dk_users' ADD `petid` smallint(5) unsigned NOT NULL default '0';

    Is that right? Because whenever I do that in SQL in PHPMySQL is just gives me 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 ''dk_users' ADD `petid` smallint(5) unsigned NOT NULL default '0

    I don't really know what other information people need but please tell me if you do require any more info.

    And also... thanks in advance :)
     
    Darkhodge, Mar 19, 2006 IP
  2. TommyD

    TommyD Peon

    Messages:
    1,397
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I ran into problems like this, where simple 'changes' were generating errors till I found the correct syntax for what I wanted to do.

    Over time I grew tired of this, like altering tables, and when with a GUI. I use MySQL CC http://freshmeat.net/projects/mysqlcc/ I found it very easy to use.

    Tip: Remember to allow access from your ip address to your mysql server via the CPanel/MySQL page.

    hth,

    tom
     
    TommyD, Mar 19, 2006 IP
  3. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #3
    Thanks for the advice! I'll check it out... :)

    But if someone does no how to fix this problem please teach me! :D
     
    Darkhodge, Mar 19, 2006 IP
  4. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #4
    
    $query = "ALTER TABLE dk_users ADD COLUMN petid int(5) UNSIGNED DEFAULT '0' NOT NULL";
    mysql_query($query);
    
    PHP:
    If you want it in a particular place say after field "x", you can use

    NOT NULL AFTER fieldname_x
     
    noppid, Mar 19, 2006 IP
  5. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #5
    Hey thanks a lot! That sorted out my problem! :)
     
    Darkhodge, Mar 19, 2006 IP