Skip to content

Commit

Permalink
Merge branch 'main' into node.js-crud-style-api
Browse files Browse the repository at this point in the history
  • Loading branch information
etimr authored Aug 31, 2023
2 parents b87b192 + 54fb78b commit 38fd92e
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions guides/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ CREATE TABLE Books (
CONSTRAINT Books_author //[!code focus]
FOREIGN KEY(author_ID) -- link generated foreign key field author_ID ...
REFERENCES Authors(ID) -- ... with primary key field ID of table Authors
ON UPDATE RESTRICT
ON DELETE RESTRICT
VALIDATED -- validate existing entries when constraint is created
ENFORCED -- validate changes by insert/update/delete
INITIALLY DEFERRED -- validate only at commit
Expand All @@ -642,9 +644,8 @@ No constraints are generated for...
* Associations annotated with `@assert.integrity: false`
* Associations which's source or target entity is annotated with `@cds.persistence.exists` or `@cds.persistence.skip`
If the association is the backlink of a **composition**, the constraint's delete rule changes to `CASCADE`. For example that applies to the `parent` association in here:
If the association is the backlink of a **composition**, the constraint's delete rule changes to `CASCADE`.
That applies, for example, to the `parent` association in here:
```cds
entity Genres {
Expand All @@ -654,7 +655,35 @@ entity Genres {
}
```
As a special case, a referential constraint with `delete cascade` is also generated
for the text table of a [localized entity](../guides/localized-data#localized-data),
although no managed association is present in the `texts` entity.
Add a localized element to entity `Books` from the previous example:
```cds
entity Books {
key ID : Integer; ...
title : localized String;
}
```
The generated text table then is:
```sql
CREATE TABLE Books_texts (
locale NVARCHAR(14) NOT NULL,
ID INTEGER NOT NULL,
title NVARCHAR(5000),
PRIMARY KEY(locale, ID),
CONSTRAINT Books_texts_texts //[!code focus]
FOREIGN KEY(ID)
REFERENCES Books(ID)
ON UPDATE RESTRICT
ON DELETE CASCADE
VALIDATED
ENFORCED
INITIALLY DEFERRED
)
```
::: warning Database constraints are not intended for checking user input
Instead, they protect the integrity of your data in the database layer against programming errors. If a constraint violation occurs, the error messages coming from the database aren't standardized by the runtimes but presented as-is.
Expand Down

0 comments on commit 38fd92e

Please sign in to comment.