Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.ms-sqlserver    |    Notorious Rube Goldberg contraption    |    19,505 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 18,380 of 19,505    |
|    Gert-Jan Strik to Gene Wirchenko    |
|    Re: SSE 2008: Referring to Other Rows Be    |
|    13 Jul 11 19:39:44    |
      XPost: microsoft.public.sqlserver.programming       From: sorrytoomuchspamalready@xs4all.nl              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              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca