...

View Full Version : How do ı add an extra field when my table is up and running ?



jeddi
03-04-2009, 06:08 PM
Hi,

I have a client table which is now active, I created it
with this type of command:


$sql = "CREATE TABLE `clients` (
`confirm` char(1) NOT NULL default '',
`type` char(1) NOT NULL default '',
`user_id` varchar(25) NOT NULL default '',
`profile` text NOT NULL default '',
...more ....
KEY `email` (`email`),
PRIMARY KEY (user_id)

) ENGINE=MyISAM DEFAULT CHARSET=latin1";


Now I want to add this extra field :


`type` char(1) NOT NULL default

What syntax do I use ?

thanks for your help :)

djm0219
03-04-2009, 06:23 PM
ALTER TABLE `clients` ADD `type` VARCHAR( 1 ) NOT NULL

Old Pedant
03-04-2009, 10:02 PM
Ummm...your CREATE TABLE *already* has created a field by that name.

So where's the typo? In your CREATE TABLE or in your question???

Regardless, the ALTER TABLE is the way to go.

jeddi
03-05-2009, 09:34 AM
Yep you are correct,

I wanted to add a new field and just copied an existing field
that was similar to what I wanted.

I should have changed its name to the new one. !
Sorry for confusion :D

Thanks for help.

jeddi
03-05-2009, 09:55 AM
Opps

Now I have gone and altered the table with:

$sql = "ALTER TABLE `clients` ADD `new` VARCHAR( 1 ) NOT NULL";

but I wanted to include a "default 'n' "

How can I now add this to the now existing field ?

Is it a "MODIFY" command ?

guelphdad
03-05-2009, 02:49 PM
Did you look in the manual?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum