Quick Delete through all tables

Hey all,

I am testing some data imports from one database to another.  Naturally, there are some errors and I need to roll back the database as I correct them, but that is somewhat time consuming and there are 350+ tables total.

In each table is a column titled 'Entered_By' and all values are 'test'.  Is there a good way to go through each table with one query and delete all rows WHERE Entered_By = 'test'  ?

Thanks!
LVL 6
Uptime Legal SystemsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
use the results of the below query for deleting the entries

SELECT 'DELETE  FROM '+NAME+ ' WHERE Entered_By = ''''test''  ' FROM sys.tables
0
Brian CroweDatabase AdministratorCommented:
try this...


EXECUTE sp_MSforeachtable
   'DELETE ? WHERE Entered_By = ''test'''

Not sure how it will handle situations where the column doesn't exist.  I recommend doing it in a test environment first if possible.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Uptime Legal SystemsAuthor Commented:
It does fail when it hits a table where the column doesn't exist but a little logic takes care of that-

Thanks to both!
0
Brian CroweDatabase AdministratorCommented:
Would you mind posting your finalized code for anyone that might reference this question?

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.