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 2000 Forums
 Transact-SQL (2000)
 cannot delete from parent

Author  Topic 

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2006-08-09 : 17:25:06
Hi friends
i've a parent table and it has 2 childs.
i want to truncate parent table without deleting any rows from childs.
yes, i tried disable FK constriant like below
alter table child1 nocheck constraint all

alter table child2 nocheck constraint all

but following line gives error
truncate table parent
the error is:
Cannot truncate table 'parent' because it is being referenced by a FOREIGN KEY constraint.
any ideas on this one?interestingly i get same error even if parent table is empty.
am using sql2005 standard edition.



Cheers

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-09 : 17:41:53
You have to drop the FK in order to perform a truncate. If you only want to disable the FK, then you'll need to perform a delete instead.

Tara Kizer
Go to Top of Page

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2006-08-09 : 17:44:55
thats what i just figured Tara.
am just wondering why it so ??
Thanks

Cheers
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-09 : 17:49:57
Because that's how Microsoft designed it for data integrity purposes.

Tara Kizer
Go to Top of Page
   

- Advertisement -