Wednesday, February 13, 2008

ISeries/AS400 Table Naming Convention

A system name will be generated if a table, view, alias, or index is created with either:
* A name longer than 10 characters
* A name that contains characters not valid in a system name
The SQL name or its corresponding system name may both be used in SQL statements to access the file once it is created. However, the SQL name is only recognized by DB2 UDB for AS/400 and the system name must be used in other environments.
If the name does not contain special characters and is longer than 10 characters, a 10-character system name will be generated as:
* The first 5 characters of the name
* A 5 digit unique number
If the SQL name contains special characters, the system name is generated as:
* The first 4 characters of the name
* A 4 digit unique number

In addition:
* All special characters are replaced by the underscore (_)
* Any trailing blanks are removed from the name
* The name is delimited by double quotes (") if the delimiters are required for the name to be a valid system name.

Examples
The system name for "??" would be "__0001"
The system name for "longtablename" would be "long0001"
The system name for "LONGTableName" would be LONG0001
The system name for "A b " would be "A_b0001"

SQL ensures the system name is unique by searching the cross reference file. If the name already exists in the cross reference file, the number is incremented until the name is no longer a duplicate.

No comments: