Unix Technical Forum

Adding a generated column

This is a discussion on Adding a generated column within the DB2 forums, part of the Database Server Software category; --> I have two related questions. Why did I have to: SET INTEGRITY FOR is3.animals OFF; before doing: alter table ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 01:47 AM
Robert Stearns
 
Posts: n/a
Default Adding a generated column

I have two related questions. Why did I have to:

SET INTEGRITY FOR is3.animals OFF;

before doing:

alter table is3.animals
add column pseudo_id
generated always as
(coalesce(regnum, cast(bhid as char(10))));

It may be of importance that bhid is the primary key of animals.

Why are other <table>s which are dependent on animals, as a foreign key,
also require:

SET INTEGRITY FOR is3.animals IMMEDIATE CHECKED FORCE GENERATED;
SET INTEGRITY FOR is3.<table> IMMEDIATE CHECKED FORCE GENERATED;

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 01:48 AM
Serge Rielau
 
Posts: n/a
Default Re: Adding a generated column

Robert Stearns wrote:

> I have two related questions. Why did I have to:
>
> SET INTEGRITY FOR is3.animals OFF;
>
> before doing:
>
> alter table is3.animals
> add column pseudo_id
> generated always as
> (coalesce(regnum, cast(bhid as char(10))));
>
> It may be of importance that bhid is the primary key of animals

If integrity for the table would not be turned off DB2 would need to do
the FORCE GENERATED processing right away in the ALTER TABLE statement.
If your table is of non trivial size this can mean a lot of logging.
Now - when expression-generated columns were added to DB2 log space was
fairly limited and we (DB2 Dev) felt that there is significant risk of
folks running out of log-space.
So we gave customers two options:
Use SET INTEGRITY to generate the values, or
use a little tool call db2gncol which generates the values using a
commit count. (and then use SET INTEGRITY to re-enable the table without
having to do FORCE GENERATED.
Now that was the past. Using SET INTEGRITY is still usefull however in
case you also want to do other changes to the table. You can batch them
up uf do all the work in one shot.
One could argue DB2 should now allow ALTER TABLE to do the whole work,
but so far it simply hasn't been more than a "yeah.. someday we'll fix
that".

>
> Why are other <table>s which are dependent on animals, as a foreign key,
> also require:
>
> SET INTEGRITY FOR is3.animals IMMEDIATE CHECKED FORCE GENERATED;
> SET INTEGRITY FOR is3.<table> IMMEDIATE CHECKED FORCE GENERATED;

If you didn't do more than add the geneated column to animals you can
take the <table> out of check pending
UNCHECKED. For sure you do NOT need FORCE GENERATED on <table>.

Cheers
Serge

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:22 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com