﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss content posted by Jorge Novo / Article Discussions / Article Discussions by Author  / Truncate All Tables / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 00:59:57 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>Just a thought, but if TRUNCATE then likely will reset SEEDS and there might be some cases where these might need to be kept?  Maybe.  Possibly.  Especially if fed through to another system or report?  Maybe.</description><pubDate>Thu, 02 Jun 2011 04:47:17 GMT</pubDate><dc:creator>Michael.Beeby</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>The script on the link below does a very good job of this without making any schema modifications, so it is a safer way to go.Truncate All Tables[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=65341[/url]</description><pubDate>Thu, 28 Oct 2010 07:28:43 GMT</pubDate><dc:creator>Michael Valentine Jones</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>i am vipul and i use this method to truncate all table from database. but constraint was not enabling by Exec sp_MSforeachtable 'alter table ? check constraint all'print 'all constraint enable'MESSAGE WILL APPEAR THAT- 'all constraint enable'BUT WHEN I CHECK THE DATABASE ALL CONSTRAINT DISABLESO WHAT I SHOULD DO ENABLE AGAIN ALL THE CONSTRAINTVIPUL SACHAN</description><pubDate>Thu, 28 Oct 2010 07:01:24 GMT</pubDate><dc:creator>vipulsachan.kiet 1412</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>Very good information on the link. Like the Blog stated there are many ways to aproach and problem..Thanks for the input.</description><pubDate>Mon, 17 Nov 2008 15:01:27 GMT</pubDate><dc:creator>Jorge Novo-@ETLDEVDBA</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>Also refer[url]http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/truncate-all-tables-part-ii.aspx[/url]</description><pubDate>Mon, 17 Nov 2008 05:36:20 GMT</pubDate><dc:creator>Madhivanan-208264</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>You can join the table with the names of tables also the statement.</description><pubDate>Mon, 17 Nov 2008 05:28:50 GMT</pubDate><dc:creator>Jorge Novo-@ETLDEVDBA</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>If not references are present on the tables:EXEC sp_MSForEachTable 'truncate TABLE ? ' will be enough to truncate all tables. the sp_MSForEachTable replace the ? for the actual table Name.</description><pubDate>Mon, 17 Nov 2008 05:23:39 GMT</pubDate><dc:creator>Jorge Novo-@ETLDEVDBA</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>/*I Do It As Follows:*/DECLARE @ROWCOUNT INTDECLARE @sSQL NVARCHAR(2000)CREATE TABLE #DropTableNames(                TableName VARCHAR(30),                TableID   INT IDENTITY(1,1) not null)INSERT INTO #DropTableNames(TableName)SELECT Table_Name FROM INFORMATION_SCHEMA.TABLES WHERE Table_Type='BASE TABLE'SET @ROWCOUNT=@@ROWCOUNTWHILE @ROWCOUNT&amp;gt;0BEGIN SELECT @sSQL='TRUNCATE TABLE '+TableName FROM #DropTableNames WHERE TableID=@ROWCOUNT SET @ROWCOUNT=@ROWCOUNT-1 EXEC SP_EXECUTESQL @sSQLEND/*My English is poor So ...Here Is No Marker*/</description><pubDate>Mon, 17 Nov 2008 02:38:36 GMT</pubDate><dc:creator>luckyHailong</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>Though it was little lateBut i appreciate your help !Thanks a lot Jorge !!I'll let you know if i need more help</description><pubDate>Thu, 28 Aug 2008 15:11:43 GMT</pubDate><dc:creator>DeepSQL-841864</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>I will gladly help you if you write about what are you trying to do. There are many uses for the script such as inserting into a bulk insert, deleting a child table, etc...</description><pubDate>Mon, 18 Aug 2008 06:42:17 GMT</pubDate><dc:creator>Jorge Novo-@ETLDEVDBA</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>Here it is:--------------4. Restore Relationships. ON delete NO action to be research ------------/* Restore relationships for delete set to no action; for update set to no action as on   original reverse eng. model */ declare @ChildTable varchar (max) -- Child table Namedeclare @ChildColumn varchar(max)-- Child column Namedeclare @MasterTable varchar (max) -- Master TAbledeclare @MasterColumn varchar (max) -- Master Column referencedeclare @sqlcmd varchar (max) -- Sql Commanddeclare @ConstraintName varchar(max) -- Constraint Namedeclare ADD_Constraint cursorfast_forward forselect distinct ConstraintName,ChildTable,ChildColumn,MasterTable,MasterColumnfrom [CoDE].[dbo].t_FK_Xref order by ConstraintNameopen ADD_Constraintfetch next from ADD_Constraintinto @ConstraintName,       @ChildTable,       @ChildColumn,       @MasterTable,     @MasterColumn     while @@Fetch_Status = 0beginbegin try select @sqlcmd = 'alter table '+@ChildTable+' with nocheck add constraint '+@ConstraintName+' foreign key '+'('+@ChildColumn+')'+' references '+@MasterTable+' ('+@MasterColumn+')'+' on delete no action on update no action'exec (@sqlcmd) fetch next from ADD_Constraintinto @ConstraintName,       @ChildTable,       @ChildColumn,       @MasterTable,     @MasterColumnend trybegin catchprint @sqlcmd+' ***** Error checkpoint 'fetch next from ADD_Constraintinto @ConstraintName,       @ChildTable,       @ChildColumn,       @MasterTable,     @MasterColumnend catchendclose ADD_ConstraintDeallocate ADD_Constraintgo---------------5. Restore CHECK Constraints--------------- -- Now enable referential integrity again--EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL' print 'Constraints Restored'</description><pubDate>Mon, 18 Aug 2008 06:40:28 GMT</pubDate><dc:creator>Jorge Novo-@ETLDEVDBA</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>Hi JorgeCould you please the 2nd part of this too.I am working on similar thing, and i am sure your code 'll help me a lot.Thanks in advance !</description><pubDate>Wed, 13 Aug 2008 11:29:24 GMT</pubDate><dc:creator>DeepSQL-841864</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>Hi JorgeIts' good.This works for me.Where is the part 2?Appreciated !!!</description><pubDate>Wed, 13 Aug 2008 08:31:47 GMT</pubDate><dc:creator>DeepSQL-841864</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>What about if all you want is to give an empty shell to a developers groups or you want to do a bulk insert into multiple tables?</description><pubDate>Tue, 03 Jun 2008 09:50:08 GMT</pubDate><dc:creator>Jorge Novo-@ETLDEVDBA</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>The proper syntax should be:EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'where the ? is been replace for the table name</description><pubDate>Tue, 03 Jun 2008 09:47:26 GMT</pubDate><dc:creator>Jorge Novo-@ETLDEVDBA</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>What's wrong with this:[code]EXEC sp_MSforeachtable @command1 = 'alter table ? nocheck constraint all'EXEC sp_MSforeachtable @command1 = 'delete from ?'EXEC sp_MSforeachtable @command1 = 'alter table ? check constraint all'[/code]</description><pubDate>Tue, 03 Jun 2008 05:50:28 GMT</pubDate><dc:creator>Eric J. Peters-451285</dc:creator></item><item><title>RE: Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>this works too: drop database FOO:)</description><pubDate>Fri, 25 Apr 2008 22:04:46 GMT</pubDate><dc:creator>jezemine</dc:creator></item><item><title>Truncate All Tables</title><link>http://www.sqlservercentral.com/Forums/Topic491023-463-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/Development/62892/"&gt;Truncate All Tables&lt;/A&gt;[/B]</description><pubDate>Fri, 25 Apr 2008 21:15:24 GMT</pubDate><dc:creator>Jorge Novo-@ETLDEVDBA</dc:creator></item></channel></rss>