Subject | Re: [firebird-support] Re: Rename a foreign key |
---|---|
Author | Рустам Муса-Ахунов |
Post date | 2017-11-16T10:58:49Z |
> Use "ALTER TABLE ... DROP CONSTRAINT ..." and then "ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY ..."I think, "slow" here is not a problem - you do it only one time, and not on regular basis.
>
> Thats no fast if the table is huge. This method I know.
If you mean that this is slow when do it manually, because of large number of FK's - you can use some automation, e.g.:
- export all FK's to *.sql script (as full CREATE CONSTRAINT queries). Or, you can execute custom query on table RDB$RELATION_CONSTRAINTS, using RDB$RELATION_NAME as base for new FK name, to build "creator" script with new names.
- using text search/replace, create separate *.sql for DROP-ing originals
- manually edit names
- then 1) execute DROP-ing script 2) execute "creator" script with new names.
Also you can try update FK names in RDB$RELATION_CONSTRAINTS table (may be with automation), but i don't know if this enough for DB to work correctly after this.