This script is fairly self-explanatory. It uses the INFORMATION_SCHEMA views to return all foreign keys within a database including the Parent or Primary Key Table and Column(s) as well as the Child Table and Column(s). This could be adapted to work for any database by creating a stored procedure that accepts an @DbName parameter and adds it to the Views referenced in the From clause to create 3-part naming.
Truncate Referenced Table
Often during the development phase one is required to truncate a table. often the task of removing foreign key references is necessary to truncate. this sp takes the pain out of it.
2009-01-19 (first published: 2009-01-05)