List:General Discussion« Previous MessageNext Message »
From:Martin Ramsch Date:August 17 1999 12:14am
Subject:Re: multiple-column unique constraint
View as plain text  
On Mon, 1999-08-16 16:50:23 -0700, Paul Schreiber wrote:
> I have a table like so:
> 
> CREATE TABLE absentee_bid (
>   ab_id int(16) DEFAULT '0' NOT NULL auto_increment,
> 
>   reg_id int(16) DEFAULT '0' NOT NULL,
>   sale_number varchar(255) NOT NULL,
>   auction_number varchar(255) NOT NULL,
> 
>   lot_description varchar(255) NOT NULL,
>   bid_amount varchar(255) NOT NULL,
> 
>   last_mod timestamp(14) NOT NULL,
> 
>   KEY (reg_id),
>   KEY (sale_number),
>   KEY (bid_amount),
> 
>   PRIMARY KEY (ab_id),
>   UNIQUE idx_ab_id (ab_id)
> );
> 
> I want to ensure the three-column combination of reg_id, sale_number
> and auction_number is unique. What's the best way to enforce this
> constraint?

I think you must put an UNIQUE index on these three columns, i.e.
add this line to your table definition:
   UNIQUE (reg_id, sale_number, auction_number)

Regards,
  Martin
-- 
Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26  E4 EC 80 58 7B 31 3A D7
Thread
multiple-column unique constraintPaul Schreiber17 Aug
  • Re: multiple-column unique constraintMartin Ramsch17 Aug
  • Re: multiple-column unique constraintChristian Mack8 Sep