Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Many tables contain a Foreign key and I would like to truncate all tables using a stored procedure.

If any one have solution kindly mail me
Posted
Updated 5-Jan-11 23:45pm
v2
Comments
Slacker007 6-Jan-11 5:46am    
Please give more information in your question. Thank you.

1 solution

You can not truncate a table which has parent-child relationship
It would be better if you first delete the records from the child tables and then from parent tables. Then reseed the identity (if any) of parent table to 0 using:
DBCC CHECKIDENT(tablename,reseed,0)
 
Share this answer
 
v2
Comments
Vivek Johari 6-Jan-11 22:26pm    
Good Answer Tarun..........

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900