Contents:
Command-Line Syntax
Created Files
Reformatting and Renaming
Table-Level CHECK Constraints
The -types File
Limitations and Known Issues
tblfix [-shortnames file] [-types file] file1 [file2 ...]
-shortnames | File 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. |
-types | File that maps type names to physical types. See below for the format. |
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:
sp_bindrule and sp_bindefault.| tbl.TBL | CREATE TABLE including PRIMARY KEY, UNIQUE, CHECK and DEFAULT constraints. |
| tbl.FKEY | ALTER TABLE commands for FOREIGN KEY constraints. |
| tbl.IX | CREATE INDEX statements. |
# are skipped.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.
These are the changes that TBLFIX makes in the extracted SQL code:
-shortnames### are handled specially, see below.-shortnames| Constraint | Name | Comment |
|---|---|---|
|
| aa_xxx | aa is usually "pk". |
| UNIQUE | aan_xxx | n is a running number, but is only included if the table has more than one one UNIQUE constraint. aa is usually either "u" or "ak". |
| CHECK | aa_xxx_colname | TBLFIX does not change the name of CHECK constraints on table level. aa is usually "check", "ck" or "ckc". |
| DEFAULT | aa_xxx_colname | aa is usually "df" or "default". |
| FOREIGN KEY | fkn_xxx_yyy | n is a running number. yyy is the short name for the table that the foreign-key constraint refers to. |
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.
-typesThe file you specify with -types
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.
IN (-1 , 1) in script from Enterprise Manager 6.5 results in syntactically incorrect SQL.
Copyright © 1996-2009,
Erland Sommarskog SQL-Konsult AB.
All rights reserved. AbaPerls is available under
Perl Artistic License
This page last updated 10-10-24 22:05