Solved

How to enable SSIS package to truncate the tables

Posted on 2014-02-11
5
1,173 Views
Last Modified: 2016-02-10
I have an SSIS package that copies data from Oracle database to the SQL Server. It works fine but I would like it to truncate SQL Server tables prior to copying data. Is that possible to accomplish with SSIS? if so, how?
0
Comment
Question by:YZlat
  • 2
  • 2
5 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 350 total points
ID: 39851048
Yes.  Prior to the data flow that pumps from Oracle to SQL, create an Execute SQL whose SQL code goes something like this:

TRUNCATE TABLE your_table_name

if we're talking more than one table, just repeat ...

TRUNCATE TABLE this_table
TRUNCATE TABLE that_table
0
 
LVL 35

Author Comment

by:YZlat
ID: 39851222
So I added "Execute SQL Task" to my Control Flow and linked it with Data Flow Task. Is that what you meant?
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39851235
Replace 'linked it' with 'so the green arrow goes FROM the Execute SQL Task TO the Data Flow Task', then yes.
0
 
LVL 34

Assisted Solution

by:Brian Crowe
Brian Crowe earned 150 total points
ID: 39851288
Considerations for using TRUNCATE TABLE:

Will not work on a table referenced by a Foreign Key constraint.  You must remove the constraint before executing TRUNCATE TABLE and then replace it after.

The table cannot participate in an indexed view.

The table cannot be published as part of transactional or merge replication.

The user executing the TRUNCATE command must have ALTER privileges on the target table or the user must have EXECUTE privileges on a procedure that executes the TRUNCATE.
0
 
LVL 35

Author Closing Comment

by:YZlat
ID: 39851494
Thanks! It worked
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now