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;
LVL 1
rgb192Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OmniUnlimitedCommented:
"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.
0
rgb192Author Commented:
I do not understand that
The key name "mid" can be any name you want.
0
OmniUnlimitedCommented:
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);"
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

rgb192Author Commented:
would there be any mysql select statements that call this unique 'putTheNameOfTheKeyHere' name
0
OmniUnlimitedCommented:
No.  Keys (also known as indexes) are simply database structures used to speed up database queries.  Generally they are set up in a table, but never specifically referred to in queries.  A unique key is simply a unique value that can be used to identify a specific record, but in your SELECT queries you would always refer to the field name (in this case message_id) and not the index or key name.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgb192Author Commented:
thanks for the key information
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.