0

If I have a view that uses a column, and I remove that column/table, the view is dropped automatically.

Is there a setting I can change such that it instead prevents the removal of the column/table, warning that it has dependencies?

Operation System: I5 or IBM i

Operating System Version: V7R1M0

[From comment] The view is not dropped; it may be marked as invalid.

SELECT * FROM QSYS2.SYSTABLES
WHERE SYSTEM_TABLE_SCHEMA = 'MYLIB' and table_name = 'MYVIEW';
--returns 1 row

ALTER TABLE MYLIB.MYTABLE DROP COLUMN TEST2;

SELECT * FROM QSYS2.SYSTABLES
WHERE SYSTEM_TABLE_SCHEMA = 'MYLIB' and table_name = 'MYVIEW';
--returns 0 rows

...That looks to me like it was dropped?

  • Insufficient information. EDIT your question to add the Db2-server operating system (z/OS, i-Series, Linux/Unix/Windows) and the Db2-version. – mao Jun 19 at 15:29
  • @mao Sorry, edited. – Sarov Jun 19 at 16:05
  • @mustaccio Looks to me like it was dropped. If it's invalid, where can I find it? I would've expected it to still be in QSYS2.SYSTABLES. – Sarov Jun 19 at 16:06
1

For i-series, at least for 7.1, you can try the RESTRICT clause of DROP COLUMN.

There is also a RESTRICT clause for DROP TABLE.

Per documentation

RESTRICT

Specifies that the column cannot be dropped if any views, indexes, triggers, or constraints are dependent on the column. 1

If all the columns referenced in a constraint are dropped in the same ALTER TABLE statement, RESTRICT does not prevent the drop.

  • Hmm. Problem with this is it requires the developer to remember to add the command every time. I also don't know how to modify System i Navigator to add the RESTRICT clause... that's probably a separate Question, though. – Sarov Jun 19 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.