SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: MySQL Command

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Command

    This may seem a silly question, but last night I was trying to add and edit columns in an existing table using MySQL commands and I couldn't get it to work.

    I would like to know how to add a column to a table, and out of interest, I would also like to know how to edit the field name of the column.

    Hope someone can help.

    Cheers

    Bobski

  2. #2
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To add new columns in your table:
    Code:
    ALTER TABLE table_name ADD (
      newcolumn CHAR(20),
      another_one CHAR(20)
    );

  3. #3
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To rename a column:
    Code:
    ALTER TABLE table_name CHANGE old_column_name new_column_name INTEGER;
    For more information about ALTER TABLE syntax, look up the MySQL documentation.

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cheers!!!

    Thanks for your help.

    Yeah, that seems good. It is annoying because I was looking up how to do this last night in a book I have and it didn't say to put the ALTER TABLE bit in front of the CHANGE part. No wonder it didn't work! Don't you just hate it when books presume you know something?!?!

    Thanks again.

    Bobski

  5. #5
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad to know I could help.

    I don't know if you are aware of this, but there is a GUI interface to administering MySQL. Try these:

    phpMyAdmin (recommended)
    MySQL Front


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
  •