Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #509

Re: SSE 2008: Referring to Other Rows Being Added

Message-ID <4E1DD860.5CE2D6C7@xs4all.nl> (permalink)
Date 2011-07-13 19:39 +0200
From Gert-Jan Strik <sorrytoomuchspamalready@xs4all.nl>
Newsgroups comp.databases.ms-sqlserver, microsoft.public.sqlserver.programming
Subject Re: SSE 2008: Referring to Other Rows Being Added
References <cpap17l6g8qsntt5703ja4m6mr8osq287i@4ax.com>

Cross-posted to 2 groups.

Show all headers | View raw


A simple/simpler solution would be to always sort the values. In other
words, to enforce that A is always lower or equal to B, both in the
table and whenever you do inserts. That way you don't need two rows for
each pair. In the table, this can be enforced with CHECK (a <= b)

-- 
Gert-Jan



Gene Wirchenko wrote:
> 
> Dear SQL'ers:
> 
>      How do I force a condition based on multiple rows?  I want the
> necessary rows to be entered in a batch.  As a simple example, what
> would be the coding of the constraint in this case following?
> 
>           create table Symmetric
>            (
>            a int not null,
>            b int not null
>            )
> 
>      Constraint: If (x,y) is in Symmetric, then (y,x) is also in
> Symmetric.
> 
>      Anyone adding rows would have to do it in a batch:
>           insert into Symmetric
>            (a,b)
>           values
>            (3,5),
>            (5,3)
> 
>      I am hoping that there is a simple answer that I am overlooking.
> Right now, all I can think of is to scan both Symmetric and the batch
> (Inserted).
> 
> Sincerely,
> 
> Gene Wirchenko

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

SSE 2008: Referring to Other Rows Being Added Gene Wirchenko <genew@ocis.net> - 2011-07-12 13:20 -0700
  Re: SSE 2008: Referring to Other Rows Being Added Erland Sommarskog <esquel@sommarskog.se> - 2011-07-12 23:55 +0200
    Re: SSE 2008: Referring to Other Rows Being Added Gene Wirchenko <genew@ocis.net> - 2011-07-12 15:37 -0700
      Re: SSE 2008: Referring to Other Rows Being Added Erland Sommarskog <esquel@sommarskog.se> - 2011-07-13 10:16 +0200
  Re: SSE 2008: Referring to Other Rows Being Added Gert-Jan Strik <sorrytoomuchspamalready@xs4all.nl> - 2011-07-13 19:39 +0200
    Re: SSE 2008: Referring to Other Rows Being Added Gene Wirchenko <genew@ocis.net> - 2011-07-13 12:14 -0700

csiph-web