Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check FK Constraints after BULK INSERT

Tags:

sql

sql-server

I have a couple of big datasets ( ~O(1TB) ), which I want to to import into my database. I use BULK INSERT to import data into temporary tables, then use SELECT and INSERT INTO to fill my real tables with the data. This is because I want to change the order of some things, and split some data files into logical tables. And if this functionality is not needed, I just BULK INSERT directly into my target table.

I would like to check if all foreign key constraints have been enforced. If I flag BULK INSERT to CHECK_CONSTRAINTS during the import stage the import process slows down to a crawl.

Is there a command to do this after the fact? I have very limited familiarity with SQL Server, and databasing in general.

Thanks in advance.

EDIT:

Suggested reading : MSDN Article

like image 879
Gleno Avatar asked Aug 27 '10 20:08

Gleno


1 Answers

To check one table:

alter table YourTable with check check constraint all

To check all tables:

exec sp_msforeachtable 'alter table ? with check check constraint all'
like image 195
Joe Stefanelli Avatar answered Sep 22 '22 18:09

Joe Stefanelli