I have four tables as xml. I'm successfully bulk loading them into 4 tables, using the SQL Server Destination, with check constraints unchecked.
The process manages to load all the data without any FK issue.
After that, how can I check the constraints ? (I've read a bit about is_not_trusted and sys.check_constraints)
ThibautHere are my conclusions so far (after googling more, checking this) etc..
It seems that I can establish back the foreign keys and check constraints by doing this on the tables:
alter table MyTable with check check constraint all
The double check will reenable the constraint and check existing data.
I came up with this request to find all the check constraints which are not trusted anymore:
select myschema.name as schema_name, mytable.name as table_name, myconstraint.name as constraint_name
from sys.check_constraints as myconstraint
inner join sys.objects as mytable on mytable.object_id = myconstraint.parent_object_id
inner join sys.schemas as myschema on myschema.schema_id = myconstraint.schema_id
where myconstraint.is_not_trusted = 1
Same applies to foreign keys by selecting from sys.foreign_keys...
Is there any caveat with the approach ?
Thibaut|||Cannot find any caveat for the moment.
The check check constraint all properly detects any error in the loaded data, and the constraints and foreign keys seems to go back to is_not_trusted = 0, just like expected.sql
No comments:
Post a Comment