SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru DeNasio's Avatar
    Join Date
    May 2001
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding extra column to a not-empty table

    Let's say I've created a table for members information (name, e-mail, etc.). My site is up and running and the table is being filled with members info. Then I realize that I want to add an extra column for icq. Is it possible to add an extra column to a not-empty table?

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. I would expect that the values for the new column in the existing rows will be set to the default value for that column (or NULL if the column is allowed to be NULL). Better check the manual

  3. #3
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    If you use the latest version of phpMyAdmin from http://www.phpwizard.net/projects/phpMyAdmin/ you can alter your tables easily. It will allow you to add and remove columns.

    Sean

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    FreakySid's got it right. The query you need is:

    ALTER TABLE tbl_name ADD COLUMN column_def [FIRST | AFTER col_name]
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


Bookmarks

Posting Permissions

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