cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

Add unique constraint to nullable relationship in CDS

Hello,

 

How can I create a unique constrain on a relationship?

 

In SQL I Would do something like

CREATE UNIQUE NONCLUSTERED INDEX 
   idx_TableAID_Unique_notnull
ON 
   TableB(TableA_ID)
WHERE
   TableA_ID IS NOT NULL;

 

I have been looking at Business Rules, but I can't find a way to choose a unique check.

 

Thanks,

Koen

1 REPLY 1
Super User
Super User

Hi @KoenJanssensPD ,

 

I don't understand the SQL query you posted but if you are looking to make sure that a look-up field on an entity contains a unique value then you can use Alternate Keys in CDS.

 

Here are a couple of links

Alternate Keys are primarily designed for assisting with integrations with other systems but one of the features of alternate keys is that they ensure uniqueness and will pop up a message to the user if they try and enter a value into a field that is not unique throughout the CDS.

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Users online (22,213)