Delete SQL table Contents with a batch file

Posted on 2007-10-19
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!

Question by:petelai100
    LVL 18

    Expert Comment

    by:Sham Haque
    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?

    Author Comment

    The version i am using is SQL Server 2000.

    LVL 18

    Accepted Solution

    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!

    Author Comment

    Thanks for your help. Worked great!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    This is my first ever Article on EE or elsewhere; therefore, please bear with me if I have some discrepancies in my writing. I read many articles and questions related to "how to pass values to SSIS packages at run-time?"  Hence, this common ques…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

    759 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

    9 Experts available now in Live!

    Get 1:1 Help Now