From: Todd Benson Date: 2008-04-12T08:43:59+09:00 Subject: Re: How to check record duplication before saving? On Fri, Apr 11, 2008 at 6:01 PM, Frank Tsao wrote: > RubyTalk@gmail.com wrote: > > If you are using Rails and migrations > > > > add_index(:table, [:column1, :column2], :unique => true) > > > > if not something like this sql > > > > CREATE UNIQUE INDEX index_name ON table(column1,column2); > > > > Becker > > 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 probably have a primary key constraint on one of the columns (unless you are using kindergarten SQLite). Example without correct caps... create table stuff ( colA int not null, colB int not null, primary key (colA, colB) ) ...or if you succumb to the idea integer IDs for the primary key are a good idea... create table stuff ( id int not null primary key, colA int not null, colB int not null, unique (colA, colB) ) Not tested. Todd