Altering Tables

This topic provides an overview of the Alter process and discusses how to perform the Alter process.

The Alter process enables you to make changes to your record definitions at any time without losing the application data that is already housed in the table. To ensure that the Alter process produces the appropriate results, be aware of when to alter an existing table and what types of conversions PeopleSoft Application Designer supports. To preserve data that is stored in tables and also reflect a recent change in the table definition, use the alter tables function to make the appropriate changes.

The alter function simplifies the process of modifying database tables when new data fields are added or when existing data fields are modified. It effectively eliminates the need to write SQL statements to perform the same function.

The alter process was specifically designed to automate the task of writing alter scripts and to protect the integrity of your database. In essence, it protects your interests by ensuring that you always control data loss. The alter function performs tests that verify whether data will be lost during the conversion of each column to be altered. Data loss normally occurs when reducing the character width of a column, dropping a column that contains data, or converting a number field to a character field that is too small.

The generated statements for this method are sent to a SQL script file, the alter script. After the script has completed, you are responsible for reapplying any SQL table DDL that you applied outside of PeopleTools. Typically, this SQL table DDL consists of GRANT and REVOKE statements that control security.

Note: In Oracle databases, procedural language/SQL (PL/SQL) is required to use the PeopleSoft Application Designer Build process.

Alter Settings

The Alter tab in the Build Settings dialog box handles the most common types of data conversions, including:

  • Increasing the length of character fields.

  • Changing a character (CHAR) field to a long character (LONG VARCHAR) field.

  • Increasing the size of number or character fields.

  • Reducing the decimal positions in number fields.

    If any column of the table has data that will be lost when truncating, the system action is determined by the Change Column Length options.

  • Changing integer-only number fields to character fields, where the character field is formatted with leading zeros.

    If any column of the table has a number that does not fit in the new character field, the system action is determined by the Change Column Length options to prevent data from being lost.

  • Adding columns to SQL tables.

  • Dropping columns from SQL tables.

  • Renaming columns in SQL tables.

  • Renaming SQL tables.

  • Moving tables to a new tablespace.

The following sections describe the types of alter conversions that you can expect to occur during the Build process.

Data Conversions

When altering tables with existing field data, PeopleSoft Application Designer handles conversions as outlined in the following table. A No value indicates that conversion cannot take place. A number in the cell following a Yes value indicates that restrictions are involved with the conversion. Refer to the corresponding numbered note following the table for additional information:

Previous Format

New Format

Char

Oracle - Long Char *

Long Char

Image

Long Char - Raw Binary

Number/ Signed Number **

Date

Time

DateTime

SmallInt ***

Integer ****

Decimal *****

Char

Yes (1)

Yes (1)

Yes (9)

No

No

No

No

No

No

No

No

Oracle - Long Char *

Yes (1)

Yes (1)

Yes

No

No

No

No

No

No

No

No

LongChar

Yes (2)(9)

Yes (2)

Yes (8)

No

No

No

No

No

No

No

No

Image

No

No

No

Yes (8)

Yes (8)

No

No

No

No

No

No

Long Char - RawBinary

No

No

No

Yes (8)

Yes (8)

No

No

No

No

No

No

SmallInt ***

Yes (5)

Yes (5)

No

No

No

No Action

Yes (4)

Yes (4)

No

No

No

Integer ****

Yes (5)

Yes (5)

No

No

No

Yes (4)

No Action

Yes (4)

No

No

No

Decimal *****

Yes (7)

Yes (7)

No

No

No

Yes (3)

Yes (3)

Yes (3)

No

No

No

Date

No

No

No

No

No

No

No

No

No Action

No

No

Time

No

No

No

No

No

No

No

No

No

No Action

No

DateTime

No

No

No

No

No

No

No

No

Yes (6)

Yes (6)

No Action

Notes

*

with length < 2000

**

where n = length and d = decimal. See notes ***, ****, and *****

***

n < 4, d = 0; n = 5, d = 0 RawBinary

****

n > 4, d = 0; n = 10, d = 0 RawBinary

*****

n > 9, d > 0

1

If data fits or data truncation is allowed.

2

Not allowed in Oracle.

3

If data fits or data truncation is allowed (for decimal portion only).

4

If data fits. No data truncation can occur, even with the option to allow data truncation.

5

If data fits.

6

If data truncation is allowed by selecting theTruncate data if field too short option on the Alter tab of the Build Settings dialog box.

7

If data fits, except if data has decimal values.

8

If image or long character change from Null to Not Null or Not Null to Null, otherwise, no action.

9

Allowed on all platforms.

Alter Process Tips

As you create and run alter scripts, keep the following information in mind.

  • Temporary tables during alter:

    When you run the Alter process, the script might create a temporary table. Temporary tables are named PSY%tablename%, and they are created in the tablespace of the altered table, that is, the tablespace currently defined in the record definition.

  • Alter process on tables containing LONGS on Oracle:

    Oracle does not allow an INSERT or SELECT FROM command if a table contains a LONG VARCHAR or LONG RAW data type. Therefore, in Oracle databases, PeopleSoft Application Designer uses an Oracle PL/SQL script to perform alters on tables that contain any type of LONG data type.

  • Alter process on Oracle on records with CHAR fields greater than 1333 bytes but less than 2000 bytes:

    For Oracle, records with CHAR fields of length greater than 1333 characters and less than 2000 characters will appear in the alter SQL script as needing to be altered, even if the information has not changed. In Oracle Unicode databases, PeopleSoft applications triple the length of a field while creating a table with a VARCHAR2 column in the database to store all three bytes of the Unicode character. In Oracle databases, VARCHAR2 can store up to 4000 bytes, which means a restriction exists to store only 1333 characters (with three bytes each).

    For example, if a LONG CHAR field is designed with a length of 1999 characters, then PeopleSoft applications interpret the field as a VARCHAR2 and create the column with a size of 1333 characters. The field length of that LONG CHAR field will be stored as 1999 in the PSRECFIELD table, but in the database it will be created with a size of 1333. So, each time a record with a LONG CHAR field of 1999 (or any value > 1333), the alter process detects the difference between the 1999 character length in PSRECFIELD and the 1333 character length in the database and generates the alter script. In addition, PeopleSoft applications also create a constraint on the VARCHAR2.

  • View dependencies:

    PeopleSoft Application Designer does not keep track of view dependencies. When the structure of a table changes, you should recreate all views. Many database environments track this information, so you might be able to determine view dependencies by issuing a query directly against the system catalog. However, if you are not the DBA, you might not have the authority to run such a query successfully.

    Also, renaming or dropping a table, view, or column might invalidate view text, dynamic view text, and possibly other stored queries.

    This table describes what happens to views by database platform:

    Database Platform

    What Happens to the Dependent Views When a Table Is Dropped?

    Do the Inoperative Views Become Operative When the Table is Recreated?

    Comments

    Microsoft SQL Server

    Becomes inoperative.

    Yes

    The dependency reported by sp_depends is incorrect until you recreate the view.

    Oracle

    Becomes inoperative.

    Yes, but only after the first use of the dependent view.

    The VIEW object that became invalid remains invalid until its first use. The Oracle catalog table for objects marks the view as valid again.

    DB2/UDB for Linux, UNIX, and Windows

    Becomes inoperative.

    No

    Views need to be recreated to make them operative.

    DB2 UDB z/OS

    Is dropped when the table is dropped.

    NA

    Views need to be recreated because the system drops them along with the table drop.

  • Alter script:

    After you invoke the Alter process, the system uses the default value that is defined in the record definition to populate the column in the altered table. The alter script that is generated contains detailed comments indicated by the (--) to assist you if you must modify the script manually.

  • Preserve storage parameters on Oracle databases:

    Alter by table rename preserves customized storage parameters for tables only (with some limitations) not for indexes, by taking DDL parameters from the system catalog.

When to Alter Tables

The following record definition changes affect synchronization with the application table and require an alter process:

  • Add or delete a field in the record.

  • Modify the length of a field.

  • Change the required status of a date, time, DateTime, or long field.

  • Rename a field.

  • Rename a record.

The Alter Table process is similar to the Create Table process except that it does not drop existing application data tables and the data that they contain.

Note: The Build process automatically alters records with more than 16 keys to support functional indexes. A warning message indicating this is included in the log file for Microsoft SQL Server and DB2/UDB for Linux, UNIX, and Windows.

Working With Alters on DB2 for z/OS

You must be aware of a variety of considerations and maintenance tasks when performing alters on DB2 UDB for z/OS. For example, you must consider:

  • Tablespace versioning.

  • Advisory Reorg Pending status.

  • Rebuild Pending status.

  • Avoiding SQL Code -4702.

These topics are discussed in detail inthe product documentation for PeopleTools: Data Management.

See Working with Alters on DB2 z/OS.

To determine tables to be altered after a field change:

  1. Create a new project.

  2. Open the altered field.

  3. Select Edit > Find Definition References.

    The referenced definitions appear in the output window.

  4. Select all of the rows that appear in the output window.

  5. Right-click the selected rows and select Insert Into Project from the pop-up menu.

To alter a table:

  1. Open the project for which you must perform an alter.

  2. From the Build menu, select the appropriate scope of your build.

    The Build dialog box appears.

  3. Select the Alter Tables option in the Build Options group box.

    Selecting the Alter Tables option automatically selects and disables the Create Indexes and Create Trigger (only if triggers are needed) option. In the Build Execute Options group box, only the Build script file option is enabled.

  4. Click the Settings button in the Build dialog box to set user-defined defaults.

    Select the appropriate alter, logging, and scripts settings.

    Note: The alter process takes care of the indexes, regardless of the Alter Table Options you select on the Alter tab of the Build Settings dialog box. In the case of the Alter by Table Rename option, the indexes are dropped automatically when the temporary table is dropped. For the Alter in Place option, the index creation process goes through the Recreate index only if modified option on the Create tab.

  5. In the Build dialog box, click Build to run the Alter Tables process.

    The length of a build process depends on the number of definitions that require building. Watch the Build Progress dialog box to monitor the Build process. When the process completes, check any errors listed in the log file.

Access the Build Settings dialog box and select the Alter tab.

Image: Build Settings dialog box: Alter tab

This example illustrates the fields and controls on the Build Settings dialog box: Alter tab. You can find definitions for the fields and controls later on this page.

Build Settings dialog box: Alter tab

Drop Column Options

These options are referenced whenever a field is deleted from a PeopleTools record definition in which data exists in the database for that column.

Field or Control

Definition

Drop column if data present

Select to drop the column and data, and write a warning to the build log.

Skip record if data present

Select to end the alter for that record and write an error message to the log. Processing continues with the next record.

Note: Whenever you select the Drop column if data present option, you run the risk of losing data, and you are prompted at runtime to confirm your selection of this option.

Change Column Length Options

Use these options whenever the length of a character column is reduced in PeopleTools and an alter could result in data truncation.

Field or Control

Definition

Truncate data if field too short

Select to alter the record and write a warning message to the build log. Note that the system does not truncate data for numeric fields because of possible data loss.

Skip record if field too short

End the alter for that record and write an error message to the build log. Processing continues with the next record.

Note: Whenever you select the Truncate data if field too short option, you run the risk of losing data, and you are prompted at runtime to confirm your selection of this option. Also, numeric fields are not truncated to avoid any loss of data.

Alter Table In Memory

If you have selected any of the Oracle In Memory options for your record or record fields, you need to select Alter Table In Memory for those options to take effect and alter the table.

See the Oracle In Memory option for records description here:Setting Use Properties.

See the Oracle In Memory option for record fields description here: Setting Record Field Use Properties.

The following example illustrates the build script generated for a table with All Fields selected on the record definition Oracle In Memory settings, and all record fields contained in that record definition are supported for IM column store processing.

ALTER TABLE PS_QE_JOBCODE_TBL INMEMORY MEMCOMPRESS FOR QUERY PRIORITY
 LOW
/
SELECT COUNT(*) FROM PS_QE_JOBCODE_TBL
/

The following example illustrates the build script generated for a table with All Fields selected on the record definition Oracle In Memory settings, and all record fields contained in that record definition are not supported for IM column store processing.

Alter in memory ALL qe book selective

ALTER TABLE PS_QE_BOOK INMEMORY MEMCOMPRESS FOR QUERY PRIORITY LOW NO
 INMEMORY (QE_BOOK_DESCR, QE_BOOK_COVER_IMG)
/
SELECT COUNT(*) FROM PS_QE_BOOK

Note that the system adds the NO INMEMORY (QE_BOOK_DESCR, QE_BOOK_COVER_IMG) statement automatically, including the fields that are not supported for IM column store processing. These fields are of type Long Character and Image, respectively.

The following example illustrates the build script generated for a table Selective Fields selected on the record definition Oracle In Memory settings, and all record fields contained in that record definition are not supported for IM column store processing. In this case, the NO INMEMORY statement will include automatically the record fields that are not supported for IM column store processing and the record fields not selected (manually) for IM column store processing.

ALTER TABLE PS_QE_BOOK INMEMORY MEMCOMPRESS FOR QUERY PRIORITY LOW NO
 INMEMORY (QE_ADDED_DT, QE_BOOK_DESCR, QE_BOOK_COVER_IMG, PSIMAGEVER)
/
SELECT COUNT(*) FROM PS_QE_BOOK
/

Alter Any

PeopleTools assumes that you want to perform alters for any modifications made to tables, so, by default, all of the check boxes in the Alter Any group box are selected. The Alter Any group box enables you to customize alter processing for adds, changes, renames, and deletes. For example, you have the flexibility to add, change, and rename fields but not to delete any removed columns. When you complete any other custom external conversion processes, you can then enable the delete processing to drop columns that are no longer defined.

Normally, you select all of these options, but during upgrades or operations requiring data conversion steps you might select a subset of actions. For example:

  • Perform alter with Adds and Changes selected.

  • Perform data conversion routines to populate the new and changed columns (perhaps from columns that are ultimately to be dropped).

  • Perform alter with Rename and Delete selected.

Alter even if no changes

Select this check box to force an alter, even if no changes were made to the tables. This check box is deselected by default. If selected, the Alter by Table Rename option in the Alter Table Options group box is automatically selected and the Alter in Place option is disabled.

Alter Table Options

When altering tables, the alter process takes care of the indexes, regardless of the Alter Table Options you select on the Alter tab of the Build Settings dialog box. In the case of Alter by Table Rename, the indexes are dropped automatically when the temporary table is dropped. For the Alter in Place option, the index creation process goes through the Recreated index only if modified option on the Create tab.

  • Alter in Place

    Selected by default. For database platforms in which Alter in Place is not supported, alter is automatically done by Alter by Table Rename (even if that option is not selected).

    Database platforms vary in the capabilities for Alter in Place table operations. This table displays the limitations for each operation by platform:

    Database

    Platform

    Add Column

    Change Column (data type, size, precision, scale, and null/not null property change)

    Rename Table

    Delete Column

    Microsoft SQL Server

    Yes *

    Yes *

    Yes *

    Yes *

    Oracle

    Yes *

    No

    Yes

    Yes *

    DB2/UDB for z/OS

    Yes *

    Yes *

    Yes *

    No

    DB2/UDB for Linux, UNIX, and Windows

    Yes *

    No

    No

    No

    * Certain restrictions might apply to this operation. Refer to the documentation for your specific database platform for more information.

  • Alter by Table Rename

    Select to create a temporary table (with changes made to the original table or its fields); the data from the original table is imported into the temporary table. The original table is then dropped and the temporary table is renamed to the original table.

    Note: For Oracle databases only, Alter by Table Rename preserves customized storage parameters for tables (with some limitations), by taking DDL parameters from the system catalog.

    If a table is renamed from the old name to a new name, the indexes that were created for the old table are moved to the new table, but the index names remain in the name of the old table. With Alter by Table Rename selected, the indexes of the old table are dropped before being renamed to the new table name, and the indexes are recreated after the table is renamed to the new name. This way, the index is created in the name of the new table.

See Working with Alters on DB2 z/OS.

To confirm your table alter:

  1. Review the SQL script that was generated by the Alter process.

    Use your native SQL command processor to open the SQL script. The script is located where you specified on the Scripts tab of the Build Settings dialog box.

  2. Run the script against your database.

  3. Use your query tool and SQL Select statements to confirm that the Alter Tables process created an application table that corresponds to your record definition and updated the system catalog tables.