Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Truncating a table
Message
From
30/09/2011 12:21:50
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01525264
Message ID:
01525266
Views:
57
>Hi,
>
>I am going through a testing phase of converting a VFP database to SQL Server database. And I expect to have to truncate SQL tables maybe several times as I fix problems. But what happens is on the first truncate (even when ALL tables of SQL Server have no records) I get message that "truncate cannot be executed because table has FOREIGN KEY constraints". I understand that it is logical not to allow breaking of a foreign key constraint but the tables have no records/rows. Therefore at this point there should not be (at least IMHO) a reason not to allow truncate. What am I missing? TIA.

You're not missing anything - that's the way it is: http://msdn.microsoft.com/en-us/library/ms177570.aspx :
"You cannot use TRUNCATE TABLE on tables that:
Are referenced by a FOREIGN KEY constraint. (You can truncate a table that has a foreign key that references itself.)
Participate in an indexed view.
Are published by using transactional replication or merge replication.
For tables with one or more of these characteristics, use the DELETE statement instead."
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform