Build a symbol table

If a column contains strings that are not unique in each row, you can move those strings to a table in which only unique copies are stored.

For example, the column contains city names. Some city names are repeated in the column, and most rows have some trailing blanks in the field. Using the VARCHAR data type eliminates the blanks but not the duplication.

You can create a table named cities, as the following example shows:
   city_name VARCHAR(40) UNIQUE

You can change the definition of the customer table so that its city column becomes a foreign key that references the city_num column in the cities table.

To insert the city of the new customer into cities, you must change any program that inserts a new row into customer. The database server return code in the SQLCODE field of the SQL Communications Area (SQLCA) can indicate that the insert failed because of a duplicate key. It is not a logical error; it simply means that an existing customer is located in that city. For more information about the SQLCA, see the IBM® Informix® Guide to SQL: Tutorial.

Besides changing programs that insert data, you must also change all programs and stored queries that retrieve the city name. The programs and stored queries must use a join to the new cities table in order to obtain their data. The extra complexity in programs that insert rows and the extra complexity in some queries is the result of giving up theoretical correctness in the data model. Before you make the change, be sure that it returns a reasonable savings in disk space or execution time.

Copyright© 2018 HCL Technologies Limited