Todd Benson
4/11/2008 11:44:00 PM
On Fri, Apr 11, 2008 at 6:01 PM, Frank Tsao <shuhao.tsao@gmail.com> 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