dbTalk Databases Forums  

Make columns read only

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Make columns read only in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ninja Li
 
Posts: n/a

Default Make columns read only - 11-06-2010 , 11:14 AM






Hi,

I would like to make certain columns in an Oracle table read only to
prevent anyone from updating the values in these columns. I can think
of creating trigger to issue error message whenever update occurs.

Are there better ways to do that? Your suggestions are appreciated.

Nick Li

Reply With Quote
  #2  
Old   
ddf
 
Posts: n/a

Default Re: Make columns read only - 11-06-2010 , 02:12 PM






On Nov 6, 1:14*pm, Ninja Li <nickli2... (AT) gmail (DOT) com> wrote:
Quote:
Hi,

* I would like to make certain columns in an Oracle table read only to
prevent anyone from updating the values in these columns. I can think
of creating trigger to issue error message whenever update occurs.

* Are there better ways to do that? Your suggestions are appreciated.

* Nick Li
I don't know of any; if you're using 10.2.0.x you could create a read-
only materialized view and if you're using 11.2 you can make the table
read only. Of course making the entire table or materialized view
read only doesn't solve your problem and Oracle hasn't yet provided a
way (through, say, the ALTER TABLE statement) to make selected columns
read-only. It would appear that a before insert trigger is the only
option you have.


David Fitzjarrell

Reply With Quote
  #3  
Old   
Gerard H. Pille
 
Posts: n/a

Default Re: Make columns read only - 11-06-2010 , 04:22 PM



ddf schreef:
Quote:
On Nov 6, 1:14 pm, Ninja Li<nickli2... (AT) gmail (DOT) com> wrote:
Hi,

I would like to make certain columns in an Oracle table read only to
prevent anyone from updating the values in these columns. I can think
of creating trigger to issue error message whenever update occurs.

Are there better ways to do that? Your suggestions are appreciated.

Nick Li

I don't know of any; if you're using 10.2.0.x you could create a read-
only materialized view and if you're using 11.2 you can make the table
read only. Of course making the entire table or materialized view
read only doesn't solve your problem and Oracle hasn't yet provided a
way (through, say, the ALTER TABLE statement) to make selected columns
read-only. It would appear that a before insert trigger is the only
option you have.


David Fitzjarrell
Or a "before update" ?

But why not "grant update (column1, column3) on my_table to ..." ? It won't
stop the table owner from updating those columns, but I suppose he could disable
the triggers too. I've never used it but it's in the manuals.

Reply With Quote
  #4  
Old   
Volker Borchert
 
Posts: n/a

Default Re: Make columns read only - 11-06-2010 , 05:12 PM



ddf wrote:
Quote:
On Nov 6, 1:14*pm, Ninja Li <nickli2... (AT) gmail (DOT) com> wrote:
* I would like to make certain columns in an Oracle table read only to
prevent anyone from updating the values in these columns. I can think
of creating trigger to issue error message whenever update occurs.

I don't know of any; if you're using 10.2.0.x you could create a read-
only materialized view and if you're using 11.2 you can make the table
read only.
Is it possible to create two views, a read-only one containing the
read-only columns and a writeable one containing the writeable columms,
and "concatenating" these into a third one?

--

"I'm a doctor, not a mechanic." Dr Leonard McCoy <mccoy (AT) ncc1701 (DOT) starfleet.fed>
"I'm a mechanic, not a doctor." Volker Borchert <v_borchert (AT) despammed (DOT) com>

Reply With Quote
  #5  
Old   
ddf
 
Posts: n/a

Default Re: Make columns read only - 11-06-2010 , 07:05 PM



On Nov 6, 6:22*pm, "Gerard H. Pille" <g... (AT) skynet (DOT) be> wrote:
Quote:
ddf schreef:





On Nov 6, 1:14 pm, Ninja Li<nickli2... (AT) gmail (DOT) com> *wrote:
Hi,

* *I would like to make certain columns in an Oracle table read only to
prevent anyone from updating the values in these columns. I can think
of creating trigger to issue error message whenever update occurs.

* *Are there better ways to do that? Your suggestions are appreciated.

* *Nick Li

I don't know of any; if you're using 10.2.0.x you could create a read-
only materialized view and if you're using 11.2 you can make the table
read only. *Of course making the entire table or materialized view
read only doesn't solve your problem and Oracle hasn't yet provided a
way (through, say, the ALTER TABLE statement) to make selected columns
read-only. *It would appear that a before insert trigger is the only
option you have.

David Fitzjarrell

Or a "before update" ?

But why not "grant update (column1, column3) on my_table to ..." ? * Itwon't
stop the table owner from updating those columns, but I suppose he could disable
the triggers too. *I've never used it but it's in the manuals.- Hide quoted text -

- Show quoted text -
It does work, and I've learned something new:

SQL> grant select, update(empno, ename, job) on mytab to gleebo;

Grant succeeded.

SQL> connect gleebo/uarm
Connected.
SQL> update bing.mytab set sal=sal*1.2;
update bing.mytab set sal=sal*1.2
*
ERROR at line 1:
ORA-01031: insufficient privileges


SQL>


David Fitzjarrell

Reply With Quote
  #6  
Old   
Gerard H. Pille
 
Posts: n/a

Default Re: Make columns read only - 11-07-2010 , 11:14 AM



ddf wrote:
Quote:
It does work, and I've learned something new:


One is never too old to learn, David, certainly not a greenhorn like you.

Reply With Quote
  #7  
Old   
Mark D Powell
 
Posts: n/a

Default Re: Make columns read only - 11-08-2010 , 12:56 PM



On Nov 6, 12:14*pm, Ninja Li <nickli2... (AT) gmail (DOT) com> wrote:
Quote:
Hi,

* I would like to make certain columns in an Oracle table read only to
prevent anyone from updating the values in these columns. I can think
of creating trigger to issue error message whenever update occurs.

* Are there better ways to do that? Your suggestions are appreciated.

* Nick Li
To add to what has already been suggested.

If you do not want certain columns in a table updated by most users
then those users should not have update privilege on the table to
begin with. You can use views and/or stored code to provide read
access and update access.

Also on 10g+ you can restrict column access via virtual private
database (VPD).

Combing VPD with views and stored procedures can do a lot to protect
data.

If certain columns should never change after initial insert then an
after update trigger could be used to stop the transaction if the
update touched certain columns. A trigger could be username aware so
as to allow the owner or production batch username to update the
target columns.

HTH -- Mark D Powell --

Reply With Quote
  #8  
Old   
Gerard H. Pille
 
Posts: n/a

Default Re: Make columns read only - 11-09-2010 , 02:23 PM



Mark D Powell wrote:
Quote:
To add to what has already been suggested.

If you do not want certain columns in a table updated by most users
then those users should not have update privilege on the table to
begin with. You can use views and/or stored code to provide read
access and update access.

Also on 10g+ you can restrict column access via virtual private
database (VPD).

Combing VPD with views and stored procedures can do a lot to protect
data.

HTH -- Mark D Powell --
Why would you waste performance that way, iso only granting update on selective columns?

Reply With Quote
  #9  
Old   
Ninja Li
 
Posts: n/a

Default Re: Make columns read only - 11-09-2010 , 11:07 PM



Thanks for all your help.

Nick

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.