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)
 Question onTruncate

Author  Topic 

AceDBA
Starting Member

13 Posts

Posted - 2004-04-01 : 18:55:39
I'm trying to truncate Table1 and I disable all the constraints on Table1 by the following command:
alter table Table1 nocheck constraint all

but I still get an error message saying "Cannot truncate table 'Database..Table1' because it is being referenced by a FOREIGN KEY constraint."

Any comments on how I can work around this?

Thanks/

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-04-01 : 18:58:06
You need to drop the FK constraints from the child tables that relate to the parent table.

Tara
Go to Top of Page

Amethystium
Aged Yak Warrior

701 Posts

Posted - 2004-04-02 : 05:37:18
[code]
DELETE Table1
Where 1 = 1
GO
[/code]

________________
Make love not war!
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-04-02 : 05:38:32
or just
delete Table1

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-04-02 : 10:27:12
You need to make sure you've backed up the database first



Brett

8-)
Go to Top of Page
   

- Advertisement -