# SQLCODE -150: Operation not allowed on this view or table

Source: https://wndsoftware.com/mainframe-errors/sqlcode-150

### SQLCODE -150: Operation not allowed on this view or table

SQLCODE -150 (SQLSTATE 42807) means the target of an INSERT, UPDATE, DELETE, MERGE or TRUNCATE is a view, system-maintained materialized query table or transition table that doesn't allow that operation. Usually it's a read-only view.


#### Other names for this code

Also written as `SQL -150`, `SQLCODE=-150`, `SQLCODE = -150`, `db2 -150`, `sqlstate 42807`, `SQL0150N`, `view is read-only db2`.


### What it means

A view is a stored query. Db2 can pass an INSERT, UPDATE or DELETE through a view to the table underneath only when each row of the view maps to exactly one row of one table. Views that join tables, use DISTINCT, GROUP BY or HAVING, aggregate functions or UNION don't meet that rule, so Db2 treats them as read-only. Changing data through one gets -150.

The same code covers two other targets. A materialized query table defined as MAINTAINED BY SYSTEM is kept up to date by REFRESH TABLE, so ordinary SQL can't change it. In a trigger, the transition tables that hold the old and new rows can be read but not changed.

For static SQL, Db2 finds this at bind time. Dynamic SQL gets it on PREPARE. Nothing is changed in either case.


### Common causes

- The view joins two or more tables, so a row of the view doesn't belong to a single table.
- The view uses DISTINCT, GROUP BY, HAVING or an aggregate function such as SUM.
- The view is built with UNION, or on top of another view that is read-only.
- The target is a system-maintained materialized query table.
- A trigger body tries to change its OLD TABLE or NEW TABLE transition table.
- A program or tool was pointed at a reporting view instead of the base table, for example through an alias.


### How to find the problem

- Check what the target really is with `SELECT TYPE FROM SYSIBM.SYSTABLES WHERE CREATOR = 'PAYPROD' AND NAME = 'EMP_SUMMARY'`. V is a view, M is a materialized query table and A is an alias.
- If it's an alias, look up TBCREATOR and TBNAME in the same row to see what it points to.
- For a view, read its definition in SYSIBM.SYSVIEWS and look for joins, DISTINCT, GROUP BY, aggregates and UNION. Check any views it's built on in the same way.
- For a trigger, look at the trigger body in SYSIBM.SYSTRIGGERS for statements that name a transition table.


### How to fix it

- Change the base table directly instead of the view.
- If the view must accept changes, create an INSTEAD OF trigger on it that applies the change to the right base tables.
- For a system-maintained MQT, change the source tables and run `REFRESH TABLE`. If the table must be changed directly, it needs to be defined as MAINTAINED BY USER.
- In a trigger, change the subject table or another table, not the transition table.
- Point programs and aliases at the updatable object, then rebind.


### What it looks like


```text
DSNT408I SQLCODE = -150, ERROR:  THE OBJECT OF THE INSERT, DELETE, UPDATE, MERGE, OR TRUNCATE
         STATEMENT IS A VIEW, SYSTEM-MAINTAINED MATERIALIZED QUERY TABLE, OR TRANSITION TABLE
         FOR WHICH THE REQUESTED OPERATION IS NOT PERMITTED
DSNT418I SQLSTATE   = 42807 SQLSTATE RETURN CODE
```


### IBM documentation

[IBM documentation: -150](https://www.ibm.com/docs/en/db2-for-zos/13.0.0?topic=codes-150). Use the documentation for your installed release.

[Report a correction to WND Software](https://wndsoftware.com/contact#message).

Technical reviewer: [Albert Joseph](https://wndsoftware.com/authors/albert-joseph), WND Software.

Last reviewed 2026-10-18 by the WND Software team. Written in our own words. For the full reference, check IBM’s Db2 for z/OS documentation for your release.


### Related codes

[SQLCODE -151 Column cannot be updated Read →](https://wndsoftware.com/mainframe-errors/sqlcode-151)
[SQLCODE -204 Undefined object name Read →](https://wndsoftware.com/mainframe-errors/sqlcode-204)
[SQLCODE -551 Not authorized for the operation Read →](https://wndsoftware.com/mainframe-errors/sqlcode-551)
[SQLCODE -117 Number of values doesn't match columns Read →](https://wndsoftware.com/mainframe-errors/sqlcode-117)

### Questions


#### How do I know if a Db2 view is read-only?

Look at its definition. A join, DISTINCT, GROUP BY, HAVING, an aggregate function or UNION makes it read-only for INSERT, UPDATE and DELETE.


#### Can I make a join view updatable?

Yes, with an INSTEAD OF trigger. The trigger receives the change and applies it to the base tables in whatever way you code.


#### Is SQL0150N on Db2 for LUW the same?

Yes. It has SQLSTATE 42807 and the same meaning, with LUW's own list of object types.

[Db2 SQLCODEs](https://wndsoftware.com/mainframe-errors/db2-sqlcodes) · [SQLCODE -138](https://wndsoftware.com/mainframe-errors/sqlcode-138) · [SQLCODE -151](https://wndsoftware.com/mainframe-errors/sqlcode-151)

[← All error codes](https://wndsoftware.com/mainframe-errors/)
