MySQL Alter table Question

Discussion in 'Databases' started by Eric1, Mar 28, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have a small data base set up with a table named info. The price column was set to int and I would like to alter it so I can place dollar amounts such as $12.25 etc. I used alter table info alter column price dec;

    The value is current Null yes.

    No luck... any ideas?

    Doc
     
  2. I tried what you suggested but still get a syntax error. Could you write out what you state. This is MySQL 5 and I used alter table info alter column price decimal;


    I thought that decimal would simply replace int(11) which is the type value in there now.





    Doc
     
  3. Welcome to the MySQL (5) monitor. Commands end with ; or \g.
    Your MySQL connection id is 2 to server version: 5.0.19-nt
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    mysql> use customer;
    Database changed
    mysql> describe info;
    +----------+-------------+------+-----+---------+-------+
    | Field | Type | Null | Key | Default | Extra |
    +----------+-------------+------+-----+---------+-------+
    | ordernum | int(11) | NO | PRI | | |
    | zip | int(5) | YES | | | |
    | name | varchar(30) | YES | | | |
    | price | int(11) | YES | | | |
    | ordrecvd | date | YES | | | |
    | shipped | date | YES | | | |
    +----------+-------------+------+-----+---------+-------+
    6 rows in set (2.47 sec)
    mysql>
    I have pricelisted which is in the Field column here. I am trying to alter the Type from int(11) to decimal so I can enter dollar values such as $12.25. I still have not been able to change the int(11) entry to decimal. I keep getting a syntax error. I have tried all combos I can think of, I guess except the right one. If you have any more ideas please spell them out as alter table info alter column price decimal;

    Thanks... The Doc
     
  4. I seem to have answered my own question. Instead of altering the value of the type field I dropped the entire column, price and then added it back in withdecimal(10,2) null so that I can now enter values such as 12.25. Not exactly how I wanted to do it, but it works...

    The Old Doc

    Joel thanks for your thoughts.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page