Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!news.xs4all.nl!not-for-mail Message-ID: <4E1DD860.5CE2D6C7@xs4all.nl> Date: Wed, 13 Jul 2011 19:39:44 +0200 From: Gert-Jan Strik Reply-To: sorry@toomuchspamalready.nl X-Mailer: Mozilla 4.79 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.databases.ms-sqlserver,microsoft.public.sqlserver.programming Subject: Re: SSE 2008: Referring to Other Rows Being Added References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 41 NNTP-Posting-Host: 82.95.107.10 X-Trace: 1310578784 news2.news.xs4all.nl 23864 82.95.107.10:11988 Xref: x330-a1.tempe.blueboxinc.net comp.databases.ms-sqlserver:509 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