#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    125
    Rep Power
    10

    Unique across 2 tables


    I was wondering if its possible to create a unique index that works across 2 tables.

    Currently I have,

    Users - username, password, email
    Temp Users - username, password, email, confirmation_code

    I want to make sure that the username doesn't get duplicated across 2 tables.

    Is there a way to do this without having to do a query to both tables?

    Thanks
    Last edited by doush.; May 21st, 2013 at 06:25 AM.
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,146
    Rep Power
    4274
    Originally Posted by doush.
    Is there a way to do this without having to do a query to both tables?
    yes, it involves creating a third table, a master table, so that these two existing tables would have their usernames as foreign keys to the primary key username of the master table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo