Subject | Re: [firebird-support] table prettifier |
---|---|
Author | Nick Upson |
Post date | 2007-01-12T09:34:42Z |
here is my simple version, in case anyone else can make use of it. I
know I don't need stmt as an output variable but it makes debugging
easier.
ALTER PROCEDURE PR_SYS_ARRANGE_TABLECOLS ()
returns (STMT Varchar(250))
AS
declare variable fpos Integer;
declare variable col_name Varchar(64);
declare variable TAB_NAME Varchar(64);
begin
/*
Author : Nick Upson
Date : 10/1/07
Purpose : arrange the columns of all tables to a pre-defined order
*/
FOR SELECT R.RDB$RELATION_NAME
FROM RDB$RELATIONS R
WHERE R.RDB$SYSTEM_FLAG = 0
INTO :tab_name
DO
BEGIN
Fpos = 0;
/* all fields into alpha order */
for select r.rdb$field_name
from rdb$relation_fields r
where r.rdb$relation_name=:tab_name
order by 1 asc
into :col_name
do
begin
fpos = fpos + 1;
STMT = 'ALTER TABLE ' || tab_name || ' ALTER ' || col_name ||
'POSITION ' || cast(fpos as varchar(4));
EXECUTE STATEMENT :STMT;
end
end
know I don't need stmt as an output variable but it makes debugging
easier.
ALTER PROCEDURE PR_SYS_ARRANGE_TABLECOLS ()
returns (STMT Varchar(250))
AS
declare variable fpos Integer;
declare variable col_name Varchar(64);
declare variable TAB_NAME Varchar(64);
begin
/*
Author : Nick Upson
Date : 10/1/07
Purpose : arrange the columns of all tables to a pre-defined order
*/
FOR SELECT R.RDB$RELATION_NAME
FROM RDB$RELATIONS R
WHERE R.RDB$SYSTEM_FLAG = 0
INTO :tab_name
DO
BEGIN
Fpos = 0;
/* all fields into alpha order */
for select r.rdb$field_name
from rdb$relation_fields r
where r.rdb$relation_name=:tab_name
order by 1 asc
into :col_name
do
begin
fpos = fpos + 1;
STMT = 'ALTER TABLE ' || tab_name || ' ALTER ' || col_name ||
'POSITION ' || cast(fpos as varchar(4));
EXECUTE STATEMENT :STMT;
end
end