?
Solved

Delete SQL table Contents with a batch file

Posted on 2007-10-19
4
Medium Priority
?
993 Views
Last Modified: 2012-05-05
Hi Experts,

I am a novice at SQL and I was wondering is it possible to delete the entire contents of an SQL table using a batch file? Basically I have some software with exports an excel spread sheet automatically into our SQL database at set times. However it uses VARCHAR for all of the formats within the table. This creates a  problem if i then import this information into excel. If I change the formats to what i want e.g. datetime, numeric etc, the next time i update the table they are all changed back to VARCHAR. This is beacuse the table is being over written each time. There is an option to merge the data into the table and this option preserves the correct formatting. However, it also adds the same data again and again. My idea is to run the software at a scheduled time say 8am and copy new information into the database, then at 9am run a batch file or something which would delete the existing data. At 10am I would you the merge option and put the data into the database.

Hope this make sense!

Peter
0
Comment
Question by:petelai100
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Sham Haque
ID: 20107775
From a (DOS) batch file, you can call osql to run a DELETE or TRUNCATE TABLE statement.

Alternatively, you can schedule a job on SQL Server to do the same.
which version/edition of SQL Server are you running?
0
 

Author Comment

by:petelai100
ID: 20107813
Hi,
The version i am using is SQL Server 2000.

Thanks
0
 
LVL 18

Accepted Solution

by:
Sham Haque earned 2000 total points
ID: 20108024
if you are using Standard edition or higher, you will have SQL Agent installed - much better to do any scheduling of SQL using that.

In Enterprise Manager, go to Management > SQL Server Agent, and right-click Jobs.

Choose New Job... then set up your schedule!
0
 

Author Comment

by:petelai100
ID: 20109724
Thanks for your help. Worked great!!
Peter
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

749 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