MySQL and ALTER TABLE, How?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

MySQL and ALTER TABLE, How?

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Post 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
Post Reply