Reputation: 5073
Let us say we've database table my_table
with the following structure
CREATE TABLE `my_table` (
`title` text,
`name` text
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `admin` VALUES ('my title', 'my name');
Now i want to update it to be with 1 extra field slogan
to be like this
CREATE TABLE `my_table` (
`title` text,
`name` text,
`slogan` text
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `admin` VALUES ('my title', 'my name', 'my slogan');
For sure if it 10 or even 100 i can do it using regex with any text editor but i it too huge for my processor to do it so i've been thinking to use PHP to update my table while it on my hosting server.
I've been thinking to use
$q1 = "CREATE TABLE `my_table`(
`slogan` text )";
mysql_query($q1) or die(mysql_error()." at row ".__LINE__);
but given me error my_table
already exist
so any help ~ thanks
Upvotes: 0
Views: 65
Reputation:
You are using CREATE TABLE
that is for creating new table but as you saying you already created table and just want to add new column slogan. So you need to use ALTER Table syntax.
So use alter query as described in other posts:
ALTER TABLE `my_table` ADD COLUMN `slogan` text
Upvotes: 1
Reputation: 65334
What you need is
ALTER TABLE `my_table` ADD COLUMN `slogan` text;
followed by lots of
UPDATE `my_table` SET `slogan`='...' WHERE `title`=' ... ';
Upvotes: 1