触发更新不同表空间中的对象

发布于 2024-08-19 10:38:45 字数 242 浏览 2 评论 0原文

我在表空间 T1 中有一个表 X,在表空间 T2 中有一个表 Y。(Oracle DB

我必须在表空间 T1 中创建一个触发器那将会, 当更新表 X 中的 C 列时, 更新表 Y(表空间 T2)中的列 D。

因为它们位于不同的表空间中,所以我的第一个问题是这可以完成吗?

如果是的话怎么办?做这样的事情需要什么特权?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅冕 2024-08-26 10:38:45

它与表空间没有太大关系。不过,您确实需要权限才能插入表(以及该特定列),并且如果表 Y 位于触发器之外的另一个模式中,则需要使用限定表名: 。 (在 Oracle 中,模式名称是拥有该对象的用户的名称)

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

编辑:
我突然想到您可能不熟悉模式和表空间之间的区别,所以这里有一个简短的解释。表空间是一个逻辑存储容器:它定义了数据文件、增长特征、日志记录类型等。表空间可以用来存储与模式对象(表、索引、视图定义、包和存储过程定义等)相关的数据。

模式是对象的集合(如表、视图、包等)。这些对象由用户拥有,据我所知,在 Oracle 中,模式的名称与拥有这些对象的用户相同。这些对象依赖于一个或多个表空间提供的存储,但表空间本身不是模式对象。

通常,架构用于对功能相关的对象进行分组(例如,您通常会为一个应用程序创建一个架构)。还可以专门创建表空间来存储一个应用程序的所有对象,但您也可以为具有不同特性的表创建不同的表空间。

通常,应用程序开发人员不必太担心表空间。您的 DBA 通常会以方便备份计划等操作的方式设置它们。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文