Re: table update best practices
- From: Ed Prochak <edprochak@xxxxxxxxx>
- Date: Tue, 14 Aug 2007 15:29:12 -0000
On Aug 13, 7:57 pm, "Frank Swarbrick" <Frank.Swarbr...@xxxxxxxxxxxxxx>
wrote:
With mainframe indexed files (VSAM) and DL/I (IMS) databases segments, which
are somewhat analogous to rows in a table, are pretty much just, umm, large
chunks of data. If you want to replace a segment with new values for one or
more fields you must replace the entire segment.
Obviously this is not the case for a relational database.
Currently we have some DL/I databases with segments that contain over 400
individual 'fields'. When migrating to DB2, I'm guessing that having an SQL
UPDATE with SET column-name = :host_var 400+ times (one for each column) is
probably not something that one would want to do. What are the
alternatives? Here's what I can think of, though none of them seem to me to
be ideal...
1) Update one column at a time, and only if it has changed. EG:
EXEC SQL
SELECT column1, column2, column3, -- etc.
INTO :column1, :column2, :column3 -- etc.
FROM A_TABLE
WHERE primary_key = :primary-key
IF column1_new not = column1
EXEC SQL
UPDATE A_TABLE
SET column1 = :column1_new
END-EXEC
END-IF
IF column2_new not = column2
EXEC SQL
UPDATE A_TABLE
SET column2 = :column2_new
END-EXEC
END-IF
2) Break up the monolithic table(s) in to many tables with a smaller numbers
of columns, where the columns in each table are more 'tightly related' in
usage then simply being related to the same primary key, and then do a
single SQL UPDATE for all columns that could have changed, even if they
haven't all changed. This way it's more likely that no columns for a
particular table require updating, and thus an update to that particular
table would not be required.
3) Can't think of a number three.
I'm guessing that number 2 is more likely the way to go, but I'm really
looking for that 'perfect world' third alternative.
Thanks,
Frank
David gave you some good advice.
I'll just suggest you get some help from an experienced Relational Db
designer.
Meanwhile as you experiment, you might look at your data for some
common things such as:
several fields all containing the same data. For example do you have
several phone number fields?
daytime_phone, fax_number, nighttime_phone, dialin_number, ...
Those should go into a table of their own and become multiple rows in
that table.
TABLE PHONE
owner
phone_number
type /* FAX, HOME, WORK, MODEM, CELL */
the Primary key would be the combined (owner, phone_number).
I just thought a specific example might help you right away.
Ed
.
- Follow-Ups:
- Re: table update best practices
- From: Frank Swarbrick
- Re: table update best practices
- References:
- table update best practices
- From: Frank Swarbrick
- table update best practices
- Prev by Date: Re: What happens after 2^32 autonum keys are exhausted?
- Next by Date: Re: Among available RDBMS. When to use ...
- Previous by thread: Re: table update best practices
- Next by thread: Re: table update best practices
- Index(es):
Relevant Pages
|