February 28, 2005 at 8:52 am
I just want to know how to turn off referential integrity for all table in my database. I have a lot of tables and it will take a lot of time if i must do it tables by tables.
Tanks a lot
February 28, 2005 at 3:07 pm
To turn off referential integrity, you have to disable or remove foreign key constraints. Try running this in Query Analyzer saving the results to a file. Then, run the file in Query Analyzer.
select 'ALTER TABLE ' + cast(table_name as char(30)) + 'NOCHECK CONSTRAINT '
+ cast(constraint_name as char(50)) + char(13)
from information_schema.constraint_table_usage
where constraint_name like 'FK%'
order by table_name, constraint_name
Do the same with this script to re-enable the constraints.
select 'ALTER TABLE ' + cast(table_name as char(30)) + 'CHECK CONSTRAINT '
+ cast(constraint_name as char(50)) + char(13)
from information_schema.constraint_table_usage
where constraint_name like 'FK%'
order by table_name, constraint_name
Greg
Greg
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply