Delete all records from a DB

  • Can anyone show me a script that can deleted every records in a db where a criteria is met without having to go into each table and delete them? example: delete every records in the db northwind where ulame='sqldummy'...

    thanks in advace..

  • There is no magic (movies are excepted). You have to go through every table that has relevant data and execute a DELETE statement with the WHERE clause.

  • or you could create a cursor with all the tables names from sysobjects, and execute the delete. But you should specify all the delete criterias for every table you want to delete.

  • If the column name is the same for all tables then

    EXEC sp_msforeachtable 'delete * from where ulame=''sqldummy'''

    will do it.

    But be carefull not to accidently delete stuff you didn't mean too.

    Edited by - antares686 on 05/09/2003 12:04:37 PM

  • No magic deletes.

    I have used the sp_msforeachtable and that works. But I also have created a cursor to do the deletes when the column names are not the same.

    Be sure you do a backup before the delete, just in case.

    Patrick

    Quand on parle du loup, on en voit la queue

  • work like a charm.. thanks for the helpful infos..

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply