Constraints ?
Posted in 2000
Topics: General Discussion
I have a table called employee which stores links between contacts and companies at particular addresses and looks like: emp_id (serial) contact_id (int) org_id (int) address_id (int) def_con (smallint (0 or 1)) I have a unique contraint set for contact_id (int) org_id (int) address_id (int) But ..... I can only have one entry at any occurance of org_id + address_id where def_con = 1. to indicate this contact is the Default contacts for this company, the rest would have a def_con of 0. How can I set a constraint for this, I can't use a unique one as when a def_con is zero it won't be unique? Many Thanks -- ^~^~^~^~^~^~^~^~^~^ Regards Mike@Bradbeer.net ^~^~^~^~^~^~^~^~^~^ --
You'll have to do the checks in INSERT and UPDATE triggers. Art S. Kagel Mike Bradbeer wrote: > > I have a table called employee which stores links > between contacts and companies at particular > addresses and looks like: > > emp_id (serial) > contact_id (int) > org_id (int) > address_id (int) > def_con (smallint (0 or 1)) > > I have a unique contraint set for > contact_id (int) > org_id (int) > address_id (int) > > But ..... I can only have one entry at any occurance of > org_id + address_id where def_con = 1. to indicate > this contact is the Default contacts for this company, > the rest would have a def_con of 0. > > How can I set a constraint for this, I can't use a unique > one as when a def_con is zero it won't be unique? > > Many Thanks > > -- > ^~^~^~^~^~^~^~^~^~^ > Regards > Mike@Bradbeer.net > ^~^~^~^~^~^~^~^~^~^ > --