A lazy sod writes...
Posted in 2000
Topics: General Discussion
Hi all, I have to find all the "unnamed" constraints in a database and rename them using a human readable name. Has anybody done this and have a script to share? ______________________________________________________ Get Your Private, Free Email at http://www.hotmail.com
Obnoxio The Clown wrote:
> Hi all,
>
> I have to find all the "unnamed" constraints in a database and rename them
> using a human readable name. Has anybody done this and have a script to
> share?
Look into the source for the print_constraints() function in
print_constraints.ec in the
source to myschema. All generated implicit constraint names follow the
pattern:
<C>#_# where <C> is the lower case letter as below and '#'s represents some
pair
of numbers:
character constraint type
--------- -----------------------------------------
u UNIQUE or PRIMARY KEY
r FOREIGN KEY
n NOT NULL
c CHECK
In the ESQL/C code I use the following sscanf to detect an implicit PRIMARY
KEY
name:
SELECT .... FROM sysconstraints.... WHERE constrtype = 'P' ......
.....
if (sscanf( sysconstraints.constrname, "u%d_%d", &a, &b ) == 2) {
-- implicit name code --
} else {
-- explicit name code --
}
Try this SQL:
SELECT *
FROM sysconstraints
WHERE constrname matches '[ncru][0-9]*_[0-9]*';
It MAY accidentally match some real constraint names but then I'd want to
rename
such oddities anyway.
Art S. Kagel