INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Installation

How can I make an existing column have a unique constraint by cDevX99
Posted: 6 Sep 01

1) Make sure that the column only conains unique values
   lets assume we are working with a table called t5.  it has two columns. id ( the primary key ) and name.  To find out if the  column contains any duplicate values make the following statements.

      select name from t5 ;
      select distinct name from t5 ;


    IF the row counts are the same then the column contains unique values only.

2)  Create a unique index as follows..

        alter table t5 add unique ( name ) ;

        If you want to give the index a name do it this way...

         alter table t5 add unique namedex ( name )

3)  Drink a beer

That's it!

    * You may optionally drink beer between and during steps one and two.

Back to MySQL FAQ Index
Back to MySQL Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close