TBLFIX

TBLFIX reads one or more files with table and type definitions, and splits the statements into the structure for table files that AbaPerls imposes.

Contents:
    Command-Line Syntax
    Created Files
    Reformatting and Renaming
    Table-Level CHECK Constraints
    The -types File
    Limitations and Known Issues

Command-Line Syntax

tblfix [-shortnames file] [-types file] file1 [file2 ...]
-shortnamesFile that defines shortnames for the table. File format: one line per table, with the table name followed by the shortname, separated by white space. You can use -- (two hyphens) to introduce a comment.
-typesFile that maps type names to physical types. See below for the format.

Created Files

TBLFIX reads one or more files with type and table definitions, generated by Enterprise Manager 6.5 or PowerDesigner, and splits the input files in this way:

TBLFIX also reformats the SQL code and changes names as we will detail in just a few moments.

TBLFIX does not handle triggers, stored procedures, views or user-defined functions, but is smart enough to ignore them. Thus you can feed TBLFIX with a script with everything in it. You can use SPFIX to extract the rest.

Reformatting and Renaming

These are the changes that TBLFIX makes in the extracted SQL code:

Table-Level CHECK Constraints

A shortcoming with PowerDesigner (including the most recent version, 9.5 as of this writing), is that you cannot define more than one table-level CHECK constraint per table. You can still include all you checks you need by AND:ing the conditions into one big constraint. But when huge constraint fires, you don't know which condition that was violated. Therefore TBLFIX has the convention that if a line in the input file starts with ###, it assumes that this is a table-level CHECK constraint. We best explain this through an example. In the Server-rule box in Powerdesigner you have entered:

### ckt_evt_hasnewins (NOT (hasnewins = 1 AND isissue = 0)),

This becomes:

CONSTRAINT ckt_evt_hasnewins CHECK
    (NOT (hasnewins = 1 AND isissue = 0)),

Thus, aftter ### follows the name of the constraint and then the conditions for the CHECK constraint with parentheses and all. If the conditions are followed by more conditions, you must have a comma at the end. You can split the condition on several lines, but do not indent in PowerDesigner, because TBLFIX will indent.

The -types File

The file you specify with -types, should consists of lines with this appearance:

typename;typedef;default;rule

Or with an example:

aba_poseffect;char(1);;@x IN ('H', 'W', ' ')
This line causes TBLFIX to create the following code:
EXEC sp_addtype aba_poseffect, 'char(1)'
go
CREATE RULE aba_poseffect_rule AS @x IN ('H', 'W', ' ')
go
EXEC sp_bindrule 'aba_poseffect_rule', 'aba_poseffect'
go

Thus, TBLFIX creates a rule, names the rule from the type by adding _rule, and binds it to the type. In this example there was no DEFAULT; but as the reader may guess, it works analoguously.

Limitations and Known Issues