views:

191

answers:

1

I have a table X in tablespace T1 and a table Y in tabelspace T2.(Oracle DB)

I have to create a trigger in tablespace T1 that will, on the event of updating a column C in table X, update column D in table Y (tablespace T2).

Because they are in different tablespaces, my first question is can this be done at all?

And if yes then how it can be done? What privileges are required to do such a thing?

A: 

It has not so much to do with the tablespace. You do need privileges to insert into the table (and that particular column) though, and if the table Y is in another schema than the trigger, you need to use the qualified table name: . (In Oracle, the schemaname is the name of the user that owns the object)

CREATE TRIGGER aur_x
AFTER UPDATE OF c ON x
FOR EACH ROW
UPDATE schema_containing_y.Y SET D = ...
;

EDIT:
It just occurred to me that you might not be familiar with the distinction between schema and tablespace, so here's a short explanation. A tablespace is a logical storage container: it dedfines datafiles, growth characteristics, logging types etc. Tablespaces can then be used as to store data associated with schema objects (tables, indexes, views definitions, but also packages and stored procedure definitions etc).

A schema is a collection of objects (like tables, views, pacakages etc.) These objects are owned by a user, and as far as i am aware, in oracle the schema has an name identical to the user that owns the objects. THe objects rely on the storage provided by one or more tablespaces, but tablespaces themselves are not schema objects.

Typically, a schema is used to group functionally related objects (for example, you'd typically create one schema for one application). Tablespaces can also be created especially to store all objects of one application, but you can also create different tablespaces for tables with different characteristics.

Normally, application developers shouldn't worry too much about tablespaces. Your DBA will typically set them up in a way that is convenient for things like backup plan.

Roland Bouman
Roland, first of all thank you for a reply in such short notice.However your solution didn't solve the problem.The situation is that X and Y (from my example) are in different tablespaces(also differnet schemas and belong to different users) but on the same database instance, the trigger, how you defined it, doesn't work. Maybe I have to have grants to do update a table in one tablespace from a trigger in the other tablespace.
milostrivun: see the 2nd sentence of my answer: "You do need prvileges tto insert int the table (and that particular column)" - I wrote INSERT Instead of UPDATE, my bad. Regarding the tablespace: like a pointed out, oracle does not care about what tablespace the table is in as long as you have proper privileges on the table. Privileges for the tablespace are needed only when creating tables in it.
Roland Bouman
Got it! It was about privileges, when I set them right It worked! Thanks again Roland!