Dropping FK constraints
Posted in 1999
Topics: General Discussion
Hi,
Is there a way to delete all FK constraints on a table with a
single SQL statement, without specifying the actual names of
all those constraints? The Informix syntax seems to require
contraint name(s) as mandatory input as in:
alter table mytable drop constraint (const1, const2,.....)
What I would like to do is to have a statement of the type:
alter table mytable drop constraint
(select constrname from sysconstraints c, systables t
where t.tabname = 'mytable' and t.tabid = c.tabid and
constrtype = 'R');
Or even a statement which drops ALL constraints (FK or otherwise)
on the table.
Thanks.
Alanoly J. Andrews.
On Tue, 18 May 1999 09:10:55 -0400, Alanoly Andrews
<AlanolyA@planmatics.com> wrote:
>Hi,
>
>Is there a way to delete all FK constraints on a table with a
>single SQL statement, without specifying the actual names of
>all those constraints? The Informix syntax seems to require
>contraint name(s) as mandatory input as in:
>
> alter table mytable drop constraint (const1, const2,.....)>
>What I would like to do is to have a statement of the type:
>
> alter table mytable drop constraint
> (select constrname from sysconstraints c, systables t
> where t.tabname = 'mytable' and t.tabid = c.tabid and
> constrtype = 'R');>
>Or even a statement which drops ALL constraints (FK or otherwise)
>on the table.
In dbaccess try:
OUTPUT TO "script.sql" WITHOUT HEADINGS
SELECT "ALTER TABLE ", systables.tabname, " DROP CONSTRAINT ",
sysconstraints.constrname, ";"
FROM sysconstraints, systables
WHERE sysconstraints.tabid = systables.tabid
AND sysconstraints.constrtype = "R"
AND systables.tabname = "prut"
;
Then run script.sql
--
Jiří Lisický ČD DATIS Olomouc
e-mail: lisicky@datis.cdrail.cz Nerudova 1
phone: +420-068-472-5496 Olomouc, Czech Republic
>>> čeština ISO-8859-2 Compatible <<<