mysql AFTER option - someone with an example?

Discussion in 'MySQL' started by falcondriver, Sep 4, 2007.

  1. #1
    hi, has someone used ALTER TABLE to move a field possition with the AFTER option ( http://dev.mysql.com/doc/refman/5.0/en/alter-table.html )?

    when i try
    ALTER TABLE mytable MODIFY field3 AFTER field1
    i get an syntax error message. same if i use CHANGE instead of MODIFY. any ideas?
     
    falcondriver, Sep 4, 2007 IP
  2. webw

    webw Peon

    Messages:
    32
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    Please paste, the syntax error message.

    Thanks,
     
    webw, Sep 4, 2007 IP
  3. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #3
    thanks, i do in 10h when im at work again - dont have access to the db from here
     
    falcondriver, Sep 4, 2007 IP
  4. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #4
    ok, the query i try to execute is:
    ALTER TABLE `data_1` change `your_age` AFTER `Your_gender`
    Code (markup):
    the error msg is not really helpfull, its just ""you have an error in your SQL Syntax near `your_gender`.

    tried it also without the ` and with MODIFY instead of CHANGE, same effect...
     
    falcondriver, Sep 4, 2007 IP
  5. Clark Kent

    Clark Kent Guest

    Messages:
    122
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If I am not remembering wrong, you can't use Alter with AFTER.
    You may use AFTER with INSERT.
    You can Insert A new field with after, Update new field with old field, than delete old field.
     
    Clark Kent, Sep 5, 2007 IP
  6. webw

    webw Peon

    Messages:
    32
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi,

    Seems you're missing the column definition:

    ALTER [IGNORE] TABLE tbl_name MODIFY [COLUMN] column_definition [FIRST | AFTER col_name]
    Code (markup):
    Try this:

    ALTER TABLE `data_1` MODIFY your_age TINYINT NOT NULL AFTER Your_gender
    Code (markup):
     
    webw, Sep 5, 2007 IP
    falcondriver likes this.
  7. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #7
    yeah, thanks, works if you specify the datatype again. thought you dont need it since i only wanna change the col position, not the datatype. rep added

    (actually i already figured that out 12 hours ago by myself, but i was to busy to post the solution :) )
     
    falcondriver, Sep 5, 2007 IP