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
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    How do ı add an extra field when my table is up and running ?

    Hi,

    I have a client table which is now active, I created it
    with this type of command:

    PHP Code:
    $sql "CREATE TABLE `clients` (
      `confirm` char(1) NOT NULL default '',
        `type` char(1) NOT NULL default '',
      `user_id` varchar(25) NOT NULL default '',
      `profile` text NOT NULL default '',    
    ...more ....
         KEY `email` (`email`),
         PRIMARY KEY (user_id)

    ) ENGINE=MyISAM DEFAULT CHARSET=latin1"

    Now I want to add this extra field :

    PHP Code:
    `typechar(1NOT NULL default 
    What syntax do I use ?

    thanks for your help

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,293
    Thanks
    4
    Thanked 202 Times in 199 Posts
    Code:
    ALTER TABLE `clients` ADD `type` VARCHAR( 1 ) NOT NULL
    Dave .... HostMonster for all of your hosting needs

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Ummm...your CREATE TABLE *already* has created a field by that name.

    So where's the typo? In your CREATE TABLE or in your question???

    Regardless, the ALTER TABLE is the way to go.

  • #4
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Yep you are correct,

    I wanted to add a new field and just copied an existing field
    that was similar to what I wanted.

    I should have changed its name to the new one. !
    Sorry for confusion

    Thanks for help.

  • #5
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Opps

    Now I have gone and altered the table with:

    $sql = "ALTER TABLE `clients` ADD `new` VARCHAR( 1 ) NOT NULL";

    but I wanted to include a "default 'n' "

    How can I now add this to the now existing field ?

    Is it a "MODIFY" command ?

  • #6
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Did you look in the manual?


  •  

    Posting Permissions

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