• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Surmounting Identity Column Challenges

    June 11, 2014 Ted Holt

    Using an identity column is a wonderful way to ensure that each row of a table (record of a physical file) has a unique identifier. It sure beats storing the next batch (invoice, transaction, etc.) number in a data area or a one-record database file. Here are a few things to keep in mind when inserting rows (writing records) into a table that has an identity column.

    1. Let the system assign the value to the identity column. You do this by specifying GENERATED ALWAYS or omitting the GENERATED option when you create the table.

    create table Sales
      ( ID                integer
                          generated always as identity,
        Invoice           dec  (9,0),
        Line              dec  (3,0),
        InvoiceDate       date,
        Customer          dec  (7,0),
        Item              char (12),
        Quantity          dec  (3,0),
        Price             dec  (5,2),
      primary key (ID))
    

    Or:

    create table Sales
      ( ID                integer as identity,
    . . . etc . . .
    

    The other option, GENERATED BY DEFAULT, allows you to assign a value of your choosing to the identity column. There are probably situations that call for this option, but I can’t think of any at the moment.

    2. One way to insert a row is to list the columns (fields), omitting the identity column.

    insert into Sales
       (Invoice, Line, InvoiceDate, Customer, Item, Quantity, Price)
    values (1001, 002, '2014-06-04', 6004, 'AB-221',  6,    5 )
    

    3. If you have a lot of columns in a table (think dozens or even hundreds of columns), you may not want to list them. If you don’t list the columns, assign the value DEFAULT to the identity column.

    insert into Sales values
    (default, 1001, 002, '2014-06-04', 6004, 'AB-221',  6,    5 )
    

    The system assigns the next value to the ID column.

    4. Combining two tables can be a challenge. What if you want to add all the rows in the sales table to the sales history table, and both tables have some of the same values in their identity columns? Don’t panic. Just add OVERRIDING USER VALUE to the statement.

    insert into SalesHistory
       overriding user value
       select * from Sales
    

    The system will ignore the values in the ID column of the Sales table and assign new values to the ID column when it inserts the Sales rows into SalesHistory.

    I have written plenty of code that retrieves the next sequential number from a data area or physical file, and I wouldn’t think of changing any of it that is still in production. But I don’t plan to use that technique again.

    RELATED STORIES

    Reader Feedback and Insights: Identity Columns and Performance

    Guarantee Unique Key Values



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    inFORM Decisions:  Register for our white paper on AP Automation.
    CloudFax400:  Moving to an IBM PureSystems™? You need our cloud-based enterprise FAX service.
    Remain Software:  IBM i Application Lifecycle Management freedom and flexibility

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ EnterpriseTech: High Performance Computing Industry News From ITJ EIC Timothy Prickett Morgan

    Watson Tapped For Mobile Apps Four-Core Power8 Box For Entry IBM i Shops Ships Early

    Leave a Reply Cancel reply

Volume 14, Number 13 -- June 11, 2014
THIS ISSUE SPONSORED BY:

ProData Computer Services
HelpSystems
WorksRight Software

Table of Contents

  • Custom Perspectives In RSE
  • Surmounting Identity Column Challenges
  • Admin Alert: Reorganizing IBM i Files To Improve Disk Performance, Part 1

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • To Comfort The Afflicted And Afflict The Comfortable
  • How FalconStor Is Reinventing Itself, And Why IBM Noticed
  • Guru: When Procedure Driven RPG Really Works
  • Vendors Fill In The Gaps With IBM’s New MFA Solution
  • IBM i PTF Guide, Volume 27, Number 27
  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle