Hi,

Excerpts from shuhao.tsao's message of Fri Apr 11 16:02:10 -0700 2008:
> Dave Thomas wrote:
> > On Apr 11, 2008, at 3:36 PM, Frank Tsao wrote:
> >> So how to check and prevent a new record that has the same columns  
> >> with
> >> same values tend to be saved in database?
> > 
> > Try creating a unique database index that spans the two columns.
> > 
> > 
> > Regards
> > 
> > 
> > Dave
> 
> Thanks for your help, but the situation in A=1, B=2 or A=2, B=1 that
> wont be accepted if using unique.
> 
> My point is that when record(A=1, B=1) was existed in database, any new
> record(A=1, B=1) can not be valided. They can be (A=1, B=2), (A=1, B=3)
> or (A=5, B=1) etc.

You could try creating a third column.  Let's suppose that you know that
all A & B values are 6 digits or less, create a unique string column
that will then contain the value of A & B sorted, zero padded and
joined.

  u = [a, b].sort.map { |i| "%06d" %i }.join

So, the database would contain 3 columns: a, b, u with u being defined
as unique in the database.

So, with a = 1; b = 2 we get u = "000001000002"

or with a = 2; b = 1 we also get u = "000001000002"


-- 
Rick Tessner
rick.tessner / gmail.com