no dup rows

Поиск
Список
Период
Сортировка
Искать

no dup rows

От:
Jodi Kanter <jkanter@virginia.edu>
Дата:
I have a linking table that has only two fields in it and both are foreign keys to other tables. I'd like to ensure that there are never any duplicate rows in this table. I was planning on creating a multi-column unique index to satisfy this requirement. Is there a more appropriate way to accomplish this or am I on the right track?>
thanks.
Jodi
--

_______________________________
Jodi L Kanter
BioInformatics Database Administrator
University of Virginia
(434) 924-2846
jkanter@virginia.edu

 

Re: no dup rows

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
Jodi Kanter wrote:
> I have a linking table that has only two fields in it and both are
> foreign keys to other tables. I'd like to ensure that there are never
> any duplicate rows in this table. I was planning on creating a
> multi-column unique index to satisfy this requirement. Is there a
> more appropriate way to accomplish this or am I on the right track?>

In "linking tables" you should usually make the entire set of columns 
the primary key.  This would solve your problem.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/

Re: no dup rows

От:
Bill Harper <bharper@solutionst.com>
Дата:
Jodi Kanter wrote:

> I have a linking table that has only two fields in it and both are 
> foreign keys to other tables. I'd like to ensure that there are never 
> any duplicate rows in this table. I was planning on creating a 
> multi-column unique index to satisfy this requirement. Is there a more 
> appropriate way to accomplish this or am I on the right track?>
> thanks.
> Jodi
> -- 
>
> /_______________________________
> //Jodi L Kanter
> BioInformatics Database Administrator
> University of Virginia
> (434) 924-2846
> jkanter@virginia.edu /
>
>  
>
Just create a primary key on the two columns, that way you get 
uniqueness and not null constraints.

-bill

Re: no dup rows

От:
Reece Hart <reece@in-machina.com>
Дата:
On Mon, 2004-08-02 at 11:32, Jodi Kanter wrote:
I have a linking table that has only two fields in it and both are foreign keys to other tables. I'd like to ensure that there are never any duplicate rows in this table. I was planning on creating a multi-column unique index to satisfy this requirement. Is there a more appropriate way to accomplish this or am I on the right track?>

Yep, that is the correct way to impose this constraint.

I give constraints meaningful names prefixed by the table name (e.g., tablename_seq_already_in_set) so that the cause of an error is more readily identifiable. This is particularly useful for insertions into complex tables with multiple constraints.

-Reece
-- 
Reece Hart, Ph.D.                  rkh@gene.com, http://www.gene.com/
Genentech, Inc.                    650-225-6133 (voice), -5389 (fax)
Bioinformatics and Protein Engineering
1 DNA Way, MS-93                   http://www.in-machina.com/~reece/
S. San Francisco, CA  94080-4990   reece@in-machina.com, GPG: 0x25EC91A0
FAQ