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
 SSIS and Import/Export (2005)
 SQL Server

Author  Topic 

Dev@nlkss

134 Posts

Posted - 2009-02-06 : 00:15:30
Hi All,
I have two tables master and child tables where child table has foreign key relation with master,
When i try to truncate child table its givving error saying
"Cannot truncate table 't2' because it is being referenced by a FOREIGN KEY constraint.".
I can use delete but Identity property is set on child table.
how can i do this.
Thanks in advance.

Satya

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-07 : 09:49:24
you cant truncate when fk is et. so use DELETE FROM table... and then in next step use DBCC CHECKIDENT (childtable) for reseting identity value
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-07 : 11:08:51
You can disable Fk and Truncate as well.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-07 : 11:54:15
something like this to disable fk

-- Disable foreign key constraint
ALTER TABLE t2 NOCHECK CONSTRAINT <yourfkconstrainthere>

Go to Top of Page
   

- Advertisement -