Link to home
Start Free TrialLog in
Avatar of compdigit44
compdigit44

asked on

What does the following option really do, drop and recreate destination table

I'm still very new in SQL. Right now I'm use SQL 2000 to and try and create a DTS package that will export contents of a table to a CSV file, but I need the DTS package to overwrite the contents of the table and not append it. Will the opetion in the wizard do this "drop and recreate destination table"?
Avatar of Chris Mangus
Chris Mangus
Flag of United States of America image

It should overwrite your CSV file.  If it doesn't for some reason you could use an Execute Process Task to delete the file before you attempt to write to it.
Avatar of gardmanIT
gardmanIT

Q.

Are you trying to drop and re-create the contents of a SQL table in the DTS and then export it to CSV or are you just trying to export an already prepared table to CSV.

If you need to drop and recreate a SQL table within DTS this is done reasonably simply, DTS will even elp you write the code!

Create a fresh DTS Package
Drop a connection object onto the page (top left icon) and set your SQL database as its source
Copy and past the connection object so you have two.
Select both then rightclick and add a Data Transformation task.
Right click the arrow between the connection objects and select properties
Set the source table you want to drop and recreate and go to the destination tab.
On the destination tab select the Create button.
This opens a window with the Create Table command you need to create the source table all over again, Copy the code to the clipboard and then select cancel (you dont want it to create the table.
Cancel out of the transform data properties box as well and delete the second connection object, this was just to get SQL to give you the code to recreate the table without youhaving to write it!

Now to your single connection object add the Execute SQL Task Object (Second section "Tasks" middle icon on the second row of objects).

Paste into the code box the create table statement from the clipboard.

eg.

CREATE TABLE [ASSHSNAPSHOT] (
[ECSTNE] decimal (7,0) NOT NULL,
[EDTNOE] decimal (5,0) NOT NULL,
[EITN14] char (6) NOT NULL,
[EITN24] char (1) NOT NULL,
[EITN34] char (4) NOT NULL,
...................
[CYCTR] decimal (15,2) NOT NULL,
[CHCTR] decimal (15,2) NOT NULL,
[SCCPB] char (1) NOT NULL )

Now all you have to do is add the drop command fro the table at the start, in this case
DROP TABLE [ASSHSNAPSHOT]
CREATE TABLE [ASSHSNAPSHOT] (
[ECSTNE] decimal (7,0) NOT NULL,
[EDTNOE] decimal (5,0) NOT NULL,
[EITN14] char (6) NOT NULL,
[EITN24] char (1) NOT NULL,
[EITN34] char (4) NOT NULL,
...................
[CYCTR] decimal (15,2) NOT NULL,
[CHCTR] decimal (15,2) NOT NULL,
[SCCPB] char (1) NOT NULL )

You now have a SQL Execute task object that will drop and re-create the table and you haven't even had to type most of it.

You can then use whatever DTS transfer  data tasks you need to repopulate the table as required.

If you just want to export a csv file it should just replace the file anyway.

Cheers,
Avatar of compdigit44

ASKER

Thanks for the reply. I'm actually trying to drop and recreate the contents of the CSV file becuase I want the data of overwrite the existing data and not append. I can find and documentation any were though to confirm that the CSV file is automatically recreated each time the export runs.
ASKER CERTIFIED SOLUTION
Avatar of gardmanIT
gardmanIT

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial