Subject Re: Multiple generators
Author Adam
--- In firebird-support@yahoogroups.com, "killerion" <jankowiak@...>
wrote:
>
> --- In firebird-support@yahoogroups.com, "Ann W. Harrison"
> <aharrison@> wrote:
> >
> > killerion wrote:
> > > In my DB, I need to keep track of different the offices of a
company,
> > > and they want to be able to create or eliminate the offices, but
> > > depending on type, location, etc... they have different types of
> > > identifiers, now I want to know if I can use multiple generators for
> > > one table or do I need to manage them in different tables... if
it is
> > > possible to do this how?
> > >
> >
> > Sure. A generator is just a value source - not tied to a table or
> > a field, except through usage. Frequently, generators are used to
> > create unique identifiers as artificial primary keys. In that case,
> > they're normally tied to a field through a trigger, though there's
> > no reason why several different tables couldn't use the same
> > generator. Having one table use two different generators to create
> > artificial keys defeats the purpose, since two generators can
> > create the same value.
> >
> > What exactly do you mean by "different types of identifiers"
> >
> > Regards,
> >
> >
> > Ann
> >
>
> They want a suffix that is an alphanumeric code used to identify
> country & type which are predetermined and a numeric code that
> determines the order in which they were created but the number must be
> counted separetly for each combination of country and type... in other
> words a storefront in mexico has a different country code than a
> storefront in the US but both have the same type code and possibly
> both would be #1 since that was the order in which they were created
>
> ie:
> mexico MXSF-0001
> US USSF-0001
>
> Jankowiak

Sure, you can create different generators to make these codes start at
1 and you will have up to 9999. But do not make these 'codes' the
primary key (that is poor design). The primary key should start at 1
and go up independently of your country code (as Bigint).

Adam