How to enforce this constraint in sql server
        Posted  
        
            by Jeremy
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jeremy
        
        
        
        Published on 2010-04-21T15:58:41Z
        Indexed on 
            2010/04/21
            16:03 UTC
        
        
        Read the original article
        Hit count: 391
        
I have a table called city, and a table called city_city. city_city correlates two city records, so it has a fromcity_id and a tocity_id. I can enforce uniqueness on fromcity_id and and tocity_id through a unique key, but how do I enforce uniqueness so that I cant insert a record if fromcity_id and tocity_id are reversed.
For example, the following records are conceptually the same:
id    fromcity_id  tocity_id
1     100          200
2     200          100
        © Stack Overflow or respective owner