SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Re-Trust Untrusted Foreign Keys and Constraints


Re-Trust Untrusted Foreign Keys and Constraints

Author
Message
shaun.stuart
shaun.stuart
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2950 Visits: 878
Comments posted to this topic are about the item Re-Trust Untrusted Foreign Keys and Constraints
Tony Trus
Tony Trus
SSC-Enthusiastic
SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)SSC-Enthusiastic (158 reputation)

Group: General Forum Members
Points: 158 Visits: 130
Thanks for the nice script. I needed to change collation on a database which involved ripping out every schema bound object and this came in quite handy with retrusting everything. Thankfully I was able to retrust foreign keys and check constraints with 0 errors. My only suggestion I can think of is to make an easier toggle between fk or ck. It could be as simple as changing your select line to include a commented out line like this:

SELECT '[' + s.name + '].' + '[' + o.name + ']' AS TableName
,i.name AS FKName
FROM sys.foreign_keys i
-- FROM sys.check_constraints i

You could go fancier such as setting a flag that allows either option or both but simply having a commented out line for future reference is nice.
Iwas Bornready
Iwas Bornready
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22832 Visits: 885
Thanks for the script.
adelio.stevanato 21159
adelio.stevanato 21159
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

Group: General Forum Members
Points: 66 Visits: 57
I am using SQL server 2014 and I have a number of tables with foreign keys where they are set as untrusted. NONE of these FK as set as "NOT FOR REPLICATION" and the command seems to run OK.

I have tried dropping the FK and re-creating and it creates ok but is always marked as is_not_trusted = 1
I have even tried creating a new column of the same datatype and creating a new FK (to the same table) and the same thing happens.
The FK MAster table looks ok.
this does not happen to ALL FK just a few (13) out many that exist.

Any ideas?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search