Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9094251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:18:28+00:00 2026-06-16T23:18:28+00:00

I have a non-directed graph table in my SQL Server (2008) database and I

  • 0

I have a non-directed graph table in my SQL Server (2008) database and I want a constraint to prevent duplicates.
My link table has 2 columns, (City1, City2), both integer references into the Cities table. I can use the following:

ALTER TABLE dbo.CityConnections
ADD CONSTRAINT CK_CityConnections_OneWayOnly UNIQUE (City1, City2)

Which does half of what I want but this does not prevent adding a “reverse” connection.

Google showed me

... UNIQUE (MIN(City1,City2), MAX(City1,City2))

Which looks like it will do exactly what I want but the syntax is invalid .

I have also tried a complicated constraint using CASE but I couldn’t get this syntax correct either.

How can I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:18:29+00:00Added an answer on June 16, 2026 at 11:18 pm

    Assuming that you can control your entry to the table, the following should work;

    ALTER TABLE dbo.CityConnections
    ADD CONSTRAINT CK_CityConnections_Unq UNIQUE (City1, City2)
    ALTER TABLE dbo.CityConnections
    ADD CONSTRAINT CK_CityConnections_OneWayOnly CHECK (City1 < City2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a weighted non-directed graph G = (V,E). Each vertex has a
I have a non scrolling UITableView inside of a larger UIScrollView. Since the table
I am trying have non-blocking I/O between a server and client. After the two
I have non-sass: .rounded-corners { -moz-border-radius-topleft: 4px; and want to do something like: $radius_size:
I have a function which returns non-void. On the caller side, I want to
Auto generating entities from a legacy database. Many of the tables have non standard
This is a supervised learning problem. I have a directed acyclic graph (DAG). Each
I have non-ascii chars in velocity template files. And when processed they are garbled.
I have non-template class with a templatized constructor. This code compiles for me. But
I have a non ode function that calculates based on the previous time step

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.