Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Truncate table generic script

Author  Topic 

scelamko
Constraint Violating Yak Guru

309 Posts

Posted - 2008-06-19 : 12:54:32
Is there any way to develop a generic Truncate table script for all the tables in the database based on foreign key relationships

for example Employee table is parent of the EmployeeSal and EmployeeBenefits, HR table is HRDivision and HRManager

My truncate statement order should be as follows I have tried using sysobjects and sysforeignkeys to develop a generic script but it didnt work out.

TRUNCATE TABLE EMPLOYEE
TRUNCATE TABLE EMPLOYEESAL
TRUNCATE TABLE EMPLOYEEBENEFITS
TRUNCATE TABLE HR
TRUNCATE TABLE HRDIVISION
TRUNCATE TABLE HRMANAGER

Is this even possible to develop a generic script for all the tables in the database.

Thanks
   

- Advertisement -