On Tue, May 3, 2016 at 1:21 AM, David G. Johnston <david.g.johnston@xxxxxxxxx> wrote:
Well.. I don't need to add a constraint if I already have a default value, that's right...WrongDavid J.
What you need is a TRIGGER function & TRIGGER that will select and assign the next users_code based on company_id.
I'm not going to write the whole thing for you, but here is part of the trigger function logic.
ELSEIF NEW.company.id = 2 THEN
NEW.users_code = NEXTVAL(c2_users_code_seq);
ELSE
< something bad happened because NEW.company_id was not valid ?
END IF;
Seriously, get yourself the books I have recommended and study them BEFORE you continue attempting to design your database.
You need a firm understanding of logical design & flow, otherwise you will be wasting your time.
--
Melvin Davidson
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.