Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

add a unique key to 'message_id' bigint() in an existing table

how to add a unique key to an existing table
`message_id` bigint(20) default NULL,


CREATE TABLE `a_messages2` (
  `a_messages_id` int(11) NOT NULL auto_increment,
  `conversation_id` bigint(20) default NULL,
  `profile_id` varchar(20) default NULL,
  `sender` varchar(20) default NULL,
  `message_id` bigint(20) default NULL,
  `message_text` varchar(1000) default NULL,
  `dateAgo` varchar(20) default NULL,
  `message_read` tinyint(4) default NULL,
  `this_user` varchar(20) default NULL,
  PRIMARY KEY  (`a_messages_id`)
) ENGINE=MyISAM AUTO_INCREMENT=7054 DEFAULT CHARSET=utf8;
Avatar of OmniUnlimited
OmniUnlimited
Flag of United States of America image

"ALTER TABLE `a_messages2`ADD COLUMN `message_id` bigint(20) default NULL AFTER `a_messages_id`"
"ALTER TABLE `a_messages2`ADD UNIQUE KEY `mid` (message_id);"

Open in new window


The key name "mid" can be any name you want.
Avatar of rgb192

ASKER

I do not understand that
The key name "mid" can be any name you want.
The key must be given a unique name.  In the example I gave you, I called it "mid", but you can call it anything you like:

"ALTER TABLE `a_messages2`ADD UNIQUE KEY `PutTheNameOfTheKeyHere` (message_id);"
Avatar of rgb192

ASKER

would there be any mysql select statements that call this unique 'putTheNameOfTheKeyHere' name
ASKER CERTIFIED SOLUTION
Avatar of OmniUnlimited
OmniUnlimited
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

thanks for the key information