Database Reference
In-Depth Information
Since this is such a common use case, many relational database systems provide cascading
constraints in the table-creation logic that do this automatically. For instance, we may have
designed our tables using the following SQL:
CREATE
CREATE TABLE
TABLE ` orders ` (
` id ` CHAR ( 5 ) NOT
NOT NULL
NULL ,
...
PRIMARY
PRIMARY KEY
KEY ( ` id ` ))
CREATE
CREATE TABLE
TABLE ` order_items ` (
` order_id ` CHAR ( 5 ) NOT
NOT NULL
NULL ,
` sku ` CHAR ( 8 ) NOT
NOT NULL
NULL ,
...
PRIMARY
PRIMARY KEY
KEY ( ` order_id ` , ` sku ` ),
FOREIGN
FOREIGN KEY
KEY ( ` order_id ` ) REFERENCES
REFERENCES orders . id
OON DELETE
DELETE CASCADE
CASCADE )
In this case, we could execute a simpler SQL statement:
DELETE
DELETE FROM
FROM orders WHERE
WHERE id = '11223' ;
However, despite the fact that we're not explicitly calling BEGIN and COMMIT , the database
system is still doing the work of a full, multitable transaction.
A developer new to MongoDB may approach an order management system by designing a
relational-style schema:
// "orders" document
{
_id : '11223' ,
...
}
// "order_items" document
{
_id : ObjectId (...),
order_id : '11223' ,
sku : '...' ,
...
}
Search WWH ::




Custom Search