Page 1 of 1

ALTER -- problems

Posted: Mon Jul 05, 2004 7:08 pm
by bishup
I need to alter the properties of a column, and make the values within both UNIQUE and KEY.

from what i have gathered so far...

ALTER TABLE `table_name` CHANGE `initial_column_name` `new_column_name` VARCHAR( 30 ) (other values...where i need to set UNIQUE and PRIMAEY KEY)


I don't know if i am writting the architecture of the code wrong or any other problem, but I was wondering if someone could type out and example for me to see that might clarify where / what I am doing wrong.


Thnx

Posted: Mon Jul 05, 2004 7:33 pm
by redmonkey
Try doing it in two steps....

Code: Select all

ALTER TABLE `table_name` CHANGE `initial_column_name` `new_column_name` VARCHAR( 30 ) NOT NULL
Followed by...

Code: Select all

ALTER TABLE `table_name` DROP PRIMARY KEY , ADD PRIMARY KEY ( `new_coloumn_name` )
If the column you are changing is already the primary key then you don't need to issue the second command.

A column can be unique or a primary key but it can't be set to both (primary keys are unique)

I take it the "MUL" means unique, Thank for

Posted: Mon Jul 05, 2004 8:18 pm
by bishup