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
 General SQL Server Forums
 New to SQL Server Programming
 Use Truncate Command on a table

Author  Topic 

amirs
Constraint Violating Yak Guru

260 Posts

Posted - 2008-06-03 : 10:44:03
hi
Can We Use Truncate Command on a table which is Refernced by Foreign Key?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-06-03 : 10:52:01
No.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

amirs
Constraint Violating Yak Guru

260 Posts

Posted - 2008-06-03 : 10:54:55
thanks for replay Harsh
but can u give me reason for this answer.
and r u applying truncate command on primary table or what?
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-06-03 : 11:56:39
From BOL:
You cannot use TRUNCATE TABLE on tables that:
  • Are referenced by a FOREIGN KEY constraint

  • Participate in an indexed view.

  • Are published by using transactional replication or merge replication.
Hope that helps.
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2008-06-03 : 12:02:29
Defeats the purpose of referential integrity. The contraint was added by someone with a particular need in mind. There really is a way to do it but I'm not going to post it. You'd wind up with orphaned data, never a good thing for your database OR your application. Look up RI on the web or in BOL to get a clearer picture about what it is and what it does for your database.

BTW - What are you asking here: "and r u applying truncate command on primary table or what?"? Harsh's response was a simple one word answer so I'm not sure what type of response your looking for with your question.

Terry
Go to Top of Page

amirs
Constraint Violating Yak Guru

260 Posts

Posted - 2008-06-04 : 00:33:55

thank for reply to all
Go to Top of Page
   

- Advertisement -