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

8/22/2022 - Mon
OmniUnlimited

"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.
ASKER
rgb192

I do not understand that
The key name "mid" can be any name you want.
OmniUnlimited

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);"
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER
rgb192

would there be any mysql select statements that call this unique 'putTheNameOfTheKeyHere' name
ASKER CERTIFIED SOLUTION
OmniUnlimited

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
rgb192

thanks for the key information