May 9, 2003 at 9:58 am
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..
May 9, 2003 at 10:27 am
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.
May 9, 2003 at 11:28 am
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.
May 9, 2003 at 12:04 pm
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
May 9, 2003 at 12:08 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
May 9, 2003 at 12:42 pm
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