advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   TIP BANK
Browse DevX
Partners & Affiliates
advertisement
advertisement
Tip of the Day
Expertise: Advanced
Language: SQL
October 3, 2005
Making Tables Read-only in Oracle
In Oracle, you can only control read/write capability for an entire tablespace, not for a single table within a tablespace. So, if you want all the tables in a tablespace to be read-only, use the following command:

ALTER TABLESPACE <tablespace_name> READ ONLY;
To reverse the change and set all the tables in the tablespace back to read-write mode, use this code:

ALTER TABLESPACE <tablespace_name> READ WRITE;
Despite that limitation, you can simulate a read-only table by simply preventing all table modifications using a trigger. To do that, create a trigger as follows.

SQL> create or replace trigger emp_sal_read_only
2 before insert or update or delete
3 on emp_sal_tbl
4 begin
5 raise_application_error (-20001, 'Table EMP_SAL_TBL is read only,
You cannot make changes to the data.');
6 end;
7 /
Trigger created.

It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com.
Already a member?





MS Sridhar
If you have a hot tip and we publish it, we'll pay you. However, due to accounting overhead we no longer pay $10 for a single tip submission. You must accumulate 10 acceptable tips to receive payment. Be sure to include a clear explanation of what the technique does and why it's useful. If it includes code, limit it to 20 lines if possible. Submit your tip here.
advertisement
advertisement