Re: Truncate one table
From: Tibor Karaszi (tibor_please.no.email_karaszi_at_hotmail.nomail.com)
Date: 03/24/04
- Next message: Adam Machanic: "Re: select rows in A that are not in B?"
- Previous message: Vishal Parkar: "Re: Truncate one table"
- In reply to: Jaygo: "Re: Truncate one table"
- Next in thread: Jaygo: "Re: Truncate one table"
- Reply: Jaygo: "Re: Truncate one table"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 24 Mar 2004 17:04:16 +0100
The error speaks for itself. If a table is referenced by a foreign key constraint, you cannot use TRUNCATE
TABLE. Either do:
DELETE FROM tblname
Or remove the foreign key, truncate the table and add back the foreign key.
-- Tibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp "Jaygo" <jaygo999.breath@hotmail.com> wrote in message news:c3sb3f$2abufh$1@ID-227643.news.uni-berlin.de... > Thanks Vishal > > That worked well on a test of one table when I tried to run the script on > another > table I got an error "Cannot truncate "table_name" because it is being > referenced > by a foreign key constraint". The last bit I tested in Northwind and was > going to restore > from backup after the operation completed. > > Any help appreciated. > > John > "Vishal Parkar" <REMOVE_THIS_vgparkar@yahoo.co.in> wrote in message > news:eo$m2xaEEHA.240@tk2msftngp13.phx.gbl... > > run command "truncate table" > > > > truncate table <table_name> (This will empty complete table and preserve > table structure.) > > > > -- > > Vishal Parkar > > vgparkar@yahoo.co.in > > > > > >
- Next message: Adam Machanic: "Re: select rows in A that are not in B?"
- Previous message: Vishal Parkar: "Re: Truncate one table"
- In reply to: Jaygo: "Re: Truncate one table"
- Next in thread: Jaygo: "Re: Truncate one table"
- Reply: Jaygo: "Re: Truncate one table"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|