Page 1 of 1

MySQL and ALTER TABLE, How?

Posted: Wed Oct 02, 2002 8:57 am
by mikebr
Newbe, I have just got MySQL started and entered my first table from a book I am reading to learh php and MySQL but I passed over one of the table entries, this is how my table looks using DESCRIBE tablename:
+---------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+----------------+
| name | varchar(20) | YES | | NULL | |
| address | varchar(30) | YES | | NULL | |
| town | varchar(20) | YES | | NULL | |
| ID | int(11) | | PRI | NULL | auto_increment |
+---------+-------------+------+-----+---------+----------------+
and this is how it should look:
+---------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+----------------+
| name | varchar(20) | YES | | NULL | |
| address | varchar(30) | YES | | NULL | |
| town | varchar(20) | YES | | NULL | |
| country | varchar(20) | YES | | NULL | |
| ID | int(11) | | PRI | NULL | auto_increment |
+---------+-------------+------+-----+---------+----------------+
so as you can see I missed out an entry of "country VARCHAR(20)," after town, I looked up a way of changing this or altering the table on the internet and found this:
"ALTER TABLE tablename alteration [, alteration ...]" and
"ADD [COLUMN[ column_description
[FIRST | AFTER column ]"
could someone please explain, do I type something in place of aleration and alteration ...? this is not covered in the book I am using.

Thanks
Mike

Posted: Wed Oct 02, 2002 9:00 am
by twigletmac
If you have a read of http://www.mysql.com/doc/en/ALTER_TABLE.html there's examples thoughout the page that show how to do different things with ALTER TABLE.

Mac

Posted: Wed Oct 02, 2002 10:04 am
by mikebr
I have found this forum to be so helpful and useful on many things that my first responce to a problem is to come here rather than php.net or mysql.com, past experiance of these sites as a newcomer has been of horror, anyway thank you, I got the problem sorted with the help of your link and some trial and error.

Mike