change a variable for all entries

Discussion in 'MySQL' started by drhyperlaur, Sep 3, 2006.

  1. #1
    hi,

    i'm not sure if it is possible but maybe someone can answer...

    i have a mysql db and in a table i have about 10.000 entries all with multiple variables... now i wonder if there is a way i could set a certain value for one of the variables

    i can go and edit each entry but i hope there is an "automated" way to do that...

    thanks in advance

    ps: if you don't understand what i mean, please ask for more details - i can give examples
     
    drhyperlaur, Sep 3, 2006 IP
  2. rosytoes

    rosytoes Peon

    Messages:
    230
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    do you mean fields instead of variables? You want to change one or more of the fields in a database to a different value? If so, you can use the sql command UPDATE.
     
    rosytoes, Sep 3, 2006 IP
  3. drhyperlaur

    drhyperlaur Well-Known Member

    Messages:
    307
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    108
    #3
    ok, i am a 0 at sql ...

    how would the command look if:

    table name: prefix_A
    camp name: name_B with values: C, D, E, F

    now let's say all values are set to C, how can i set them all to D ?

    i use phpmyadmin (if it metters)
     
    drhyperlaur, Sep 3, 2006 IP
  4. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #4
    Do you have a column in your table where there are values that range from C to F, and you want them all the be D?... Please explain in detail a little better please.
     
    smatts9, Sep 3, 2006 IP
  5. drhyperlaur

    drhyperlaur Well-Known Member

    Messages:
    307
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    108
    #5
    indeed, i have a column with 4 variables, the default one is A (for example) and i want them all to be B (for example)... but not to change the default one...
     
    drhyperlaur, Sep 4, 2006 IP
  6. rosytoes

    rosytoes Peon

    Messages:
    230
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Is this what you mean, you have a table, there is a column in there where the values could be A, B, C, D, E, F.
    Example:
    Row 1 - B
    Row 2 - A
    Row 3 - C
    Row 4 - F
    Row 5 - D
    Row 6 - A
    Row 7 - C
    You want everything that is not A to be changed to B (for example)? Your last sentence is very confusing.
     
    rosytoes, Sep 4, 2006 IP
  7. drhyperlaur

    drhyperlaur Well-Known Member

    Messages:
    307
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    108
    #7
    sorry, i know nothing about sql that's why i can't explain it as you'd wish ...

    i'll give it one more try :)

    so:

    there is a table called prefix_A with more fields and one of the fields contains entries which can take 4 values (A, B, C and D) and the default one is A so i want to change them all to B

    but i aslo want to keep the default value A for the next entries (which will be added from now on...)

    if it still doesn't make sens, please give an example of update command so maybe i can try it
     
    drhyperlaur, Sep 4, 2006 IP
  8. rosytoes

    rosytoes Peon

    Messages:
    230
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    UPDATE prefix_A set name_B="B";
    Code (markup):
    will set everything in the column name_B to B. This will of course only affect the records already in the database. This will not affect future inserts. You can set a default of "A" in the table structure and from then on, if no value is entered, the database will automatically set it to "A".
     
    rosytoes, Sep 4, 2006 IP
  9. drhyperlaur

    drhyperlaur Well-Known Member

    Messages:
    307
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    108
    #9
    hehe it worked :) i just needed to change the "B" to 'B'.. maybe because of the phpmyadmin version or something.. it didn't work with ""

    thanks a lot !
     
    drhyperlaur, Sep 4, 2006 IP