CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2003
    Location
    Central Indiana, USA
    Posts
    3,882

    MySQL 4 query assistance

    Hi.

    I want to change the parameter of one field in my products table. The product's owner is currently listed as "master," and I want to change it to "Susan." I'm not sure what type of query I should use: SELECT, ALTER TABLE, CHANGE....?

    I've come up with this skeleton:

    SELECT ,master, from product CHANGE to ,Susan,

    Would something like that work? I don't think my syntax is correct and this is too important a table for me to mess up.

    Thanks!
    Susan Ross Moore
    Assistant Editor
    Jupitermedia.com

    Serving www.codeguru.com and www.developer.com.

  2. #2
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: MySQL 4 query assistance

    if you just want to change the name of the resulting column for the current query only (the change will not be permanent)
    Code:
     SELECT master as Susan from product
    if you want to change the name of the column permanently you'll need to alter the table:
    Code:
    alter table product change master suzan same_column_definition_for_master
    you can know the same_column_definition_for_masterusing this query:
    Code:
    show create table product
    you can send the result of the above query (show create...) so I can write the complete alter query for you.
    you can (and better) use a tool like phpmyadmin (web based) or MySQL Administrator which is free and good
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  3. #3
    Join Date
    Aug 2003
    Location
    Central Indiana, USA
    Posts
    3,882

    Re: MySQL 4 query assistance

    Okay. Let me see if I can do this for you.

    The table name is _products, the column is provider, and each cell in that column is named master. I want to change master to Susan.

    Here is the results of the SELECT query you had me perform in phpadmin:

    SELECT provider AS Susan
    FROM `_products`
    WHERE 1
    LIMIT 0 , 30
    Susan Ross Moore
    Assistant Editor
    Jupitermedia.com

    Serving www.codeguru.com and www.developer.com.

  4. #4
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: MySQL 4 query assistance

    Ok
    the situation looks clearer
    you want to updated the (values) of the column provider in the _products table from 'master' to 'suzan'


    at first : take a backup of the table (easy using phpmyadmin)
    then run this query:
    Code:
    update _products Set provider =  'suzan' where provider = 'master'
    now all records with provider = master will change to suzan.
    tell me if it works fine or if you find any problems, don't forget to take a backup before running queries that change a lot of records.
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  5. #5
    Join Date
    Aug 2003
    Location
    Central Indiana, USA
    Posts
    3,882

    Re: MySQL 4 query assistance

    The query worked perfectly. Thank you very much!!!
    Susan Ross Moore
    Assistant Editor
    Jupitermedia.com

    Serving www.codeguru.com and www.developer.com.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured