Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Changing a field data type

    Hi gents,

    Is there a way to change a field from a VARCHAR to something else? Say, I wanted to change a field that I set to VARCHAR(100) and want to change it to INT(11)?

  • #2
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 1 Time in 1 Post
    Code:
    ALTER TABLE  `user` CHANGE  `DoB`  `DoB` INT( 11 ) NOT NULL
    PHP Code:

    $sql 
    "ALTER TABLE `user` CHANGE `DoB` `DoB` INT(11) NOT NULL"

  • Users who have thanked doomed2020 for this post:

    FlashDance (10-31-2011)

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    Thanks doomed2020, and welcome to the forums!

  • #4
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    I tried using the command like this, but it didn't work.

    alter table feedback change id id int(11) not null auto_increment, primary key (id);

    Do you know why this happened?

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    You can't make two changes at once. Your ", primary key (id)" is thus rejected.

    The funny thing is, if you had simply coded
    Code:
    alter table feedback change id id int(11) not null auto_increment primary key;
    it would work. You do not *HAVE* to use a separate specification when defining a primary key.

    Even in CREAT TABLE you can do
    Code:
    CREATE TABLE tbl (
        id int auto_increment primary key,
        name varchar(100), ....
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    FlashDance (10-31-2011)

  • #6
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    I see, yes it makes sense.

    Thanks for your help, Old Pedant.


  •  

    Posting Permissions

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