Subject Re: [firebird-support] Computed column for primary key
Author Alan J Davies
> CREATE TABLE accounts
> (
> dept_id INT,
> build_id INT,
> account_nbr COMPUTED BY (dept_id || '-' || build_id),
> PRIMARY KEY(account_nbr)
> );
If every record has this character "-", it becomes meaningless in an
index. All you need is this:
PRIMARY KEY (dept_id, build_id); (make sure each field is not null)
The dept_id and build_id must be a unique combination, but I guess you
already know that.
For new records, dept_id is a known value, but the build_id could be the
value of a generator, which involves less error-checking, otherwise you
will need to code against duplicates etc.
If you want to display the results of a select, that's when you would
use your construct:
select dept_id || '-' || build_id
from accounts
where "records meet my conditions"

Alan J Davies
Aldis

On 09/06/2011 07:37, Thomas Steinmaurer wrote:
> > CREATE TABLE accounts
> > (
> > dept_id INT,
> > build_id INT,
> > account_nbr COMPUTED BY (dept_id || '-' || build_id),
> > PRIMARY KEY(account_nbr)
> > );
> >
> > It complains that I cannot use an computed column for the index. How
> would I fix this?
> >
> > Also, is using computed columns slow vs storing the actual value?
>
> You can't create an index on a computed column.
>
> --
> With regards,
>
> Thomas Steinmaurer
> Upscene Productions
> http://www.upscene.com
> http://blog.upscene.com/thomas/
>
> Download LogManager Series, FB TraceManager today!
> Continuous Database Monitoring Solutions supporting
> Firebird, InterBase, Advantage Database, MS SQL Server
> and NexusDB!
>
> > ------------------------------------
> >
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >
> > Visit http://www.firebirdsql.org and click the Resources item
> > on the main (top) menu. Try Knowledgebase and FAQ links !
> >
> > Also search the knowledgebases at http://www.ibphoenix.com
> >
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > Yahoo! Groups Links
> >
> >
> >
>
>
> ------------------------------------------------------------------------
>
> No virus found in this message.
> Checked by AVG - www.avg.com <http://www.avg.com>
> Version: 10.0.1382 / Virus Database: 1511/3688 - Release Date: 06/08/11
>