Board index » delphi » How to eliminate double field entry???

How to eliminate double field entry???

Hi All,

I have a table named BILLOFMATERIAL which consists of three fields:
PITEM CHAR(15) /* parent item */
CITEM CHAR(15) /* child item */
QTYPER NUMERIC(5,2) /* qty per child item used by parent item */

I would like to have unique combinations of PITEM & CITEM, example:

PITEM,CITEM,QTYPER
A,B,10
A,C,10
A,D,10
A,E,5

If the user tries to add another record with
A,C,10 or
A,B,10
The table should refuse the entry.
Is it possible to somehow encode this with the table structure.

Thanks in advance for any help

Cheers

Trajano Roberto

 

Re:How to eliminate double field entry???


Hi,

you can create a 'UNIQUE CONSTRAINT'.

If you're using InterBase Workbench, go to the Constraint Editor, select the
table and click 'New Constraint'.

If not, type:

ALTER TABLE mytable
ADD CONSTRAINT constraintname UNIQUE
  (col1, col2, col3)

--
Martijn Tonies
Upscene Productions

InterBase Workbench - The Developer Tool for InterBase
http://www.interbaseworkbench.com

"Experience is what you get when you didn't get what you wanted"

"Trajano Roberto" <amst...@smartchat.net.au> schreef in bericht
news:3c04b409_2@dnews...

Quote
> Hi All,

> I have a table named BILLOFMATERIAL which consists of three fields:
> PITEM CHAR(15) /* parent item */
> CITEM CHAR(15) /* child item */
> QTYPER NUMERIC(5,2) /* qty per child item used by parent item */

> I would like to have unique combinations of PITEM & CITEM, example:

> PITEM,CITEM,QTYPER
> A,B,10
> A,C,10
> A,D,10
> A,E,5

> If the user tries to add another record with
> A,C,10 or
> A,B,10
> The table should refuse the entry.
> Is it possible to somehow encode this with the table structure.

> Thanks in advance for any help

> Cheers

> Trajano Roberto

Other Threads