0

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

1
  • To be honest, I don't quite get the question Commented Mar 4, 2012 at 21:41

3 Answers 3

2

Try that:

ALTER TABLE my_table ADD slogan text; 
Sign up to request clarification or add additional context in comments.

Comments

1

What you need is

ALTER TABLE `my_table` ADD COLUMN `slogan` text; 

followed by lots of

UPDATE `my_table` SET `slogan`='...' WHERE `title`=' ... '; 

Comments

1

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.