Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Truncate Table when foreign key present 1

Status
Not open for further replies.

kyledunn

Programmer
Jan 2, 2001
145
US
I have Table1 that has a primary key and Table2 that has a foreign key that references the primary key in Table1. I can truncate Table2. Because Table1 is still being referenced by a foreign key constraint I can not truncate it even though there are no records in the referencing table. I can use DELETE FROM Table1 to remove the records and I also thought if the table becomes very large that I could drop the constraint, truncate the table and then reconstruct the constraint. What is the most efficient (quickest) way to truncate a table that is being referenced by a foreign constraint?
 
The most efficient is as you metioned drop the constraint, truncate the table and then reconstruct the constraint.

Rick Cole.
 
Sorry forgot to mention using the truncate method will make any subsequent restore of the database with transaction logs unworkable until the next full backup has been completed. So be careful if it is on a production databases.

Rick Cole.
 
This is a table in an OLAP cube build that gets completely rebuilt with each new data import so quickly deleting the table is the objective and no log is necessary. Thanks for your response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top