Skip to Content

Referential Integrity in HANA XS CDS.

Oct 28, 2016 at 05:47 AM


avatar image


Been trying to understand how to enforce data integrity at DB level with CDS. I have made a lot of study and I understand as a design principle CDS does not have foreign key constraints.

Then is the data integrity maintained at application level?

From other posts and study there is a lot of feedback that not having referential integrity would ultimately result in chaos at some point. The only advantage is that DB operations are faster.

Doesn't this cause an overhead in the application layer.

With HANA bringing everything into the DB layer, isnt this against the HANA philosophy?

Adding constraints after creating CDS seems like rework and doesn't come under delivery units too. For applications which has a complicated DB, with lots of references and relations, It's better to use SQL rather than CDS?

Correct me if I am wrong and please explain :)

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Thomas Jung
Nov 01, 2016 at 01:19 PM

CDS is designed this way on purpose. The associations are not enforced by database constraints but should be checks/used in the Application Layer. For instance the associations are enforced by the XSDS/sap-cds library. They will also planned to be enforced by the new CDS based OData framework which is being developed in XS Advanced.

Show 5 Share
10 |10000 characters needed characters left characters exceeded

Thanks Thomas,

In order for me to understand better can you explain why it was designed this way?


I'm not sure what else I can provide here. That was a design decision. The teams weighed the options and chose this approach. In general foreign constraints aren't well liked by our development teams because they are too transparent. From the application logic it isn't obviously they exists. This is likely the main reasoning behind the approach they took.


Thanks Thomas !!


Good question and too transparent answer)

Did you tried XSA Constraints (.hdbconstraint) HDI plug-in? As it supposed to transform a design-time constraint into a constraint on database tables.

It would be also interesting to hear SAP reps (personal) opinion on HDI .hdbconstraint and .hdbindex best practices and future.


Although constraints still aren't well liked we have given in and delivered the design time object you mention - hdbconstraint. They can be applied on top of the CDS association. I've added them in the most recent version of the openSAP course content: