How do I change all entries in a row in mysql?

Discussion in 'PHP' started by mnymkr, Mar 24, 2009.

  1. #1
    I need to change the default value for a mysql row from 0 to 1 for a thousand entries.

    What is the best way for me to do this?
     
    mnymkr, Mar 24, 2009 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    mysql_query(UPDATE table_name SET row_name = '1');

    should work?
     
    PoPSiCLe, Mar 24, 2009 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    If there are other values in the row that you don't want to change use this:

    mysql_query(UPDATE table_name SET row_name = '1' WHERE row_name = '0');
     
    jestep, Mar 24, 2009 IP
  4. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you actually want to change the default value - that is, the value that goes into the field when an 'insert' is done that doesn't specify a value for that field, then you need to use ALTER TABLE.

    example:
    ALTER TABLE mytable MODIFY myfield INT NOT NULL DEFAULT 1;
    Code (markup):
     
    SmallPotatoes, Mar 24, 2009 IP
  5. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,328
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #5
    i need to do both

    i need to alter the values already there and change it for any more incoming defualts
     
    mnymkr, Mar 24, 2009 IP