SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Nov 2007
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    unique combination?

    Hey,

    Is it possible to have a unique combination of two data types?

    For example

    table_a:

    id - id1 - id2

    1 - 100 - 264

    user id 1 and user id 2 will always be unique to each other. No other row can contain 264 - 100, vice versa.

    any help

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    declare a compound UNIQUE constraint on (id1,id2)

    if this is mysql, then, in your application logic, make sure you always insert ~only~ where id1 < id2, never the other way around

    if this isn't mysql, you can add a CHECK constraint for ( id1 < id2 )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2007
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got it, thanks.


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
  •