How to change column datatype when it has dependencies?

It is not directly possible with Firebird. If you try to do it with ALTER TABLE command, you would get an error like this:

This operation is not defined for system tables.
Error 335544351, unsuccessful metadata update
Column EMP_NO from table EMPLOYEE is referenced in SET_EMP_NO

Some commercial tools use hacks on system tables make it possible, however, make sure your database can be backed up and restored after those. Also, make sure you can extract metadata for entire database, and recreate it afterwards. The reason is that system table modifications are tricky, and one small error can show up months later when you completely forget about it. Even if it works, problems can occur, as your stored procedures and triggers are compiled into binary BLR and they might seem to work, until you try to alter them once and use the original SQL source which is only stored as text in metadata tables. Even if those changes are well tested on databases, newer versions of Firebird might change the structure of system tables and some new rules might go un-noticed by tool makers.

The safe way to do it is to remove all dependencies: drop dependent foreign keys, check constraints and views, alter procedures and triggers to have empty bodies and then change the column. When done, alter the column and recreate all the dependencies. This will ensure that you catch any incompatibilities with the change you made to column's database, as the creation of those objects would probably fail in such case.

This might seem like too much work, so use tools to help you. For example, FlameRobin has such feature called Generate Rebuild Script. It is available at the bottom of properties page for each table. It also generates such scripts automatically when you select ALTER VIEW command.

Do you find this FAQ incorrect or incomplete? Please e-mail us what needs to be changed. To ensure quality, each change is checked by our editors (and often tested on live Firebird databases), before it enters the main FAQ database. If you desire so, the changes will be credited to your name. To learn more, visit our add content page.

If you are a commercial tool maker and your tool features a great way to handle the issue written about in this FAQ, please check out our advertisement page.

All contents are copyright © 2007-2017 unless otherwise stated in the text.

Links   Firebird   News   FlameRobin   Home Inventory powered by FB  
Add content   Advertise   About  

 Installation and setup
 Backup and restore
 Connectivity and API
 Errors and error codes