SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Making a second column unique

    Is there a way to set another column in a MySQL database as unique (no duplicate entries) besides the Primary Key column? I have a standard auto incrementing column which is set as the Primary Key, but I also have a column for part numbers where I don't want any duplicates.

    Also, if there is such a method, would using it affect the performance of the database?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,015
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Code:
    alter table yourtable
    add constraint unique uneek2ndindx (secondcol)
    yes, it will affect the performance of the database -- the database will now reject dupes, whereas before it didn't!

    oh, you mean execution time? yeah, it will be slower by a few picoseconds
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •