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;
MySQL Server

Avatar of undefined
Last Comment
rgb192
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
rgb192
Flag of United States of America image

ASKER

I do not understand that
The key name "mid" can be any name you want.
Avatar of OmniUnlimited
OmniUnlimited
Flag of United States of America image

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
rgb192
Flag of United States of America image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of rgb192
rgb192
Flag of United States of America image

ASKER

thanks for the key information
MySQL Server
MySQL Server

MySQL is an open source, relational database management system that runs as a server providing multi-user access to a number of databases. Acquired by Oracle in 2009, it is frequently used in combination with PHP installations, powering most of the WordPress installations.

49K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo