web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM 2011/2013 - Foreign Key Constraint is_not_for_replication and is_not_trusted

(0) ShareShare
ReportReport
Posted on by 240

Hello all, about the is_not_for_replication=1 and is_not_trusted=1 foreign key constraints

The following query will show all the FK Constraints on a given database that are not trusted.

SELECT '[' + s.name + '].[' + o.name + '].[' + i.name + ']' AS keyname
      , is_disabled, is_not_trusted, is_not_for_replication
  FROM sys.foreign_keys       AS i
  JOIN sys.objects                  AS o ON i.parent_object_id = o.object_id
  JOIN sys.schemas                  AS s ON o.schema_id = s.schema_id
WHERE i.is_not_trusted = 1 

This can happen for 2 reasons.
1. The constraints were created without the "CHECK CHECK" option
OR
2. The is_not_for_replication=1 already, which automatically makes it untrusted.

In CRM 2011/2013 I have noticed that for ALL of them even in the the ootb databases, they are all set to is_not_for_replication and is_not_trusted to true.

There are few articles out there that say this is bad mojo and a client of ours is now looking into it. 

Here is an article on it in general SQL, but not specific to CRM:
https://sgdevaney.wordpress.com/2012/04/06/sys-foreign_keys-is_not_trusted/

Our client (rightfully so) thinks they may benefit performance wise from setting all the constraints to = 0 for both options, which unfortunately can only happen by dropping and recreating the constraints, which i'm pretty sure is unsupported.

Their other question is why on earth would MS default it this way? Again, I checked our "Virgin 2013 and 2011" dbs on our servers and sure enough other than 25 constraints owned by the metadataschema, all were untrusted...which causes performance issues like this guy talks about in the article....crazy.

Summary = Why is it this way? Does it need to remain this way? Is it supported to make it not this way?

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi John,

    It is unsupported to recreate the constraints.

    We will further investigate in order to provide you with more information on the reasons behind these foreign key constraints.

  • jklemetsrud Profile Picture
    240 on at

    I figured it was not supported, ok cool! and Thanks for getting back with me. I'll be waiting on the update to inform our client and let them know it's not supported.

    Thanks again!

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi John,

    The issues is addressed in CRM 2015 RTM.If you run the query on a pre-2013 deployment, you will see ~472 results are returned, but in CRM 2015 only 10-11 are returned.  The ones that remain are all ActivityPointerBase foreign keys that are marked as logical, so these are expected.  

    Our recommendation is to open a support ticket so we can start an internal investigation and check if it would be supported to backport these changes to previous versions, as well as determine if there is a supported regeneration script that could be used on pre-2015 databases.

    If you decide to open a support ticket (which should be free of charge as it is a code change we need to study), please let me know the number so we can follow up internally.

  • Community Member Profile Picture
    on at

    Hi John,

    What is the status on your side?  My colleagues informed me that they have prepared and tested the script which would fix the issue you reported in CRM 2013. In order to be able to provide you the script, we will need a support ticket which is free of charge as it was a bug. Let us know if you open one so we do the internal follow up. Thanks!

  • jklemetsrud Profile Picture
    240 on at

    Hello Oana, I'm sorry I didn't see this until so late. I will talk with the client and see if it's something that interests them as they may be deciding it's ok to wait until they upgrade to 2015, assuming an "upgrade" would solve the issue. If upgrading would not, then of course we would indeed need a script to possibly fix the issue. Also, I want to give you an extreme thank you for looking into this so deeply. It is really appreciated.

  • jklemetsrud Profile Picture
    240 on at

    Also, was going to ask, will that script work on 2011 as well, they are upgrading soon, but was just curious. Seems like it's more of a DB script than CRM Version specific.

  • Community Member Profile Picture
    on at

    We need to test it on 2011 before being able to confirm it works. But your observation is correct.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Shidin Haridas Profile Picture

Shidin Haridas 2

#2
Abdullah13 Profile Picture

Abdullah13 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans