On 9 Feb 2011, at 6:12pm, Black, Michael (IS) wrote: > I have a need to create a unique bi-directional relationship. > > You can think of it as pairings of people who eat dinner together. > > > > create table t(i int, j int); > > insert into t(1,2); > > insert into t(2,1); << should give an error because the pairing of 1-2 > already exists. > > insert into t(3,2); << OK > > insert into t(3,1); << OK > > insert into t(1,3); << should be error
Make a trigger that when you insert a record into the table inserts one with the columns swapped. Use "INSERT OR FAIL" so you don't get recursive looping. The other way to do it would be to create a view that views the actual table both ways around (try UNION). That will be faster for creating the data and slower for consulting it. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users