Truncate all tables in SQL Server db

From: Partha (mcp111_at_hotmail.com)
Date: 03/18/04


Date: Thu, 18 Mar 2004 07:43:27 -0800

Microsoft provides a built-in stored procedure for such
tasks

use the following command

sp_msforeachtable 'truncate table ?'

this will truncate all the tables in your database.

>-----Original Message-----
>I'm moving VB 6 project from Access to SQL Server. First
step is to continue
>to use Access with linked to SQL Server tables. A made
already all required
>changes in code.
>I have prepared a copy of Access database with data in
SQL Server by running
>DTS. Then I restored lost primary keys and made some
other changes.
>A also prepared a copy of Access database without data
(just linked tables).
>Then because the current Access db is in use all the time
I will need to
>stop its use for as short as possible time to transfer
data to SQL Server
>and start to use a database with linked tables.
>I need to truncate all tables in SQL Server first and
then to run DTS to
>transfer the most current data from Access.
>Is there any way to truncate all tables in SQL Server in
one step? Or I need
>to run "truncate table table1" then "truncate table
table2" and so on? Due
>to number of tables it's going to take a lot of time
which is not desirable.
>
>Thank you
>Vlad
>
>
>.
>



Relevant Pages

  • Re: SQL 2000 - Connection Error with DTS Packages
    ... After I changed all SQL Server 'Database Connection' steps in each of my DTS ... Package" option when you right click a DTS package name in ME. ...
    (microsoft.public.sqlserver.dts)
  • Re: Large table structure
    ... >> Tibor Karaszi, SQL Server MVP ... >>> Got a database in from a client that surpasses the 2 gig limit. ... >>>> Tibor Karaszi, SQL Server MVP ... >>>>> you truncate the table it's ...
    (microsoft.public.sqlserver.server)
  • Re: file conversion from SQL Server to Access
    ... You want to take data and table structure from SQL Server to Access? ... You can also have DTS create the destination tables for you. ... Is there a Northwind database ... >> www.konesans.com - Consultancy from the people who know ...
    (microsoft.public.sqlserver.dts)
  • Re: Audit of sql server
    ... The DTS database transfer makes sense now. ... >> SQL Server will not check on this for you. ... >> Compiles each query but does not execute it. ...
    (microsoft.public.sqlserver.programming)
  • Re: cannot open database requested in login
    ... Is the connection object using Windows Authentication? ... Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) www.SQLDTS.com - The site for all your DTS needs. ... > I have a DTS replication which truncates the destination> of one database and copies all the rows from the source> table of another database of same serverin> first step. ...
    (microsoft.public.sqlserver.dts)