To configure an Execute SQL Task to drop and re-create a destination table
After you configure the task, that text will display on the design sheet, under the Execute SQL task icon.
In this example, you can use either connection because both Cn1 and Cn2 connect to the same database. However, it is better practice to use the destination connection.
IF EXISTS (SELECT * from sysobjects
WHERE id = object_id(N'[Northwind].[dbo].[Categories2]') AND
OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP Table [Northwind].[dbo].[Categories2]
GO
CREATE TABLE [Northwind].[dbo].[Categories2]
(
[CategoryID] [int] IDENTITY (1,1) NOT NULL PRIMARY KEY,
[CategoryName] [nvarchar] (15) NOT NULL,
[Description] [ntext],
[Picture] [image]
)
GO
This SQL code checks for the presence of the destination table. If the table does not exist, it is created. If the table exists, it is dropped and re-created. Without this package step, the same data from the source table is appended to the destination table every time the package is run.