ALTER T开发者_运维技巧ABLE "APPLICATIONS_SRV_STORAGE"
ADD CONSTRAINT "APPL_SRV_STORAGE_APPLICAT_FK1"
FOREIGN KEY ("APP_ID")
REFERENCES "APPLICATIONS" ("APP_ID")
ON DELETE CASCADE
ENABLE;
Does it mean: When something on table APPLICATIONS is deleted, delte altough the entry in APPLICATION_SRV_STORAGE?
The addition of DELETE CASCADE means that when a row in APPLICATIONS is deleted, any rows in APPLICATIONS_SRV_STORAGE that reference its APP_ID will also be deleted.
Yes. APPLICATIONS
will be considered the parent and APPLICATIONS_SRV_STORAGE
will be the child, the connection being made through APP_ID
. When the parent is deleted, then all the children will also be deleted (cascading).
Reference: http://www.techonthenet.com/oracle/foreign_keys/foreign_delete.php (Couldn't find the official one.)
This adds a new constraint with the name APPL_SRV_STORAGE_APPLICAT_FK1
to the table APPLICATIONS_SRV_STORAGE
.
The constraint itself is that for every value in the column APPLICATIONS_SRV_STORAGE.APP_ID
, there must be a matching value in APPLICATIONS.APP_ID
. APPLICATIONS.APP_ID
can contain values not contained in APPLICATIONS_SRV_STORAGE.APP_ID
.
In addition to that, if an APP_ID
is deleted from the table APPLICATIONS
, then all rows from APPLICATIONS_SRV_STORAGE
with the same ID are deleted as well.
At creation time, the constraint is enabled (Oracle allows you to disable constraints temporarily).
精彩评论