ALTER -- problems

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
bishup
Forum Newbie
Posts: 6
Joined: Mon Jul 05, 2004 7:08 pm

ALTER -- problems

Post 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
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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)
bishup
Forum Newbie
Posts: 6
Joined: Mon Jul 05, 2004 7:08 pm

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

Post by bishup »

Post Reply