sql - Run a DELETE statement certain table names stored in a table -
i have table stores names of tables - tablenames. i'd run delete statement on of tables (deleting rows tables represent, not removing them tablenames). thought do
delete (select tablename tablesnames ...) deletetables but keep getting incorrect syntax error. thought iterating through table in while loop , storing using variable, i'm hoping there's more simpler way. specifically, microsoft sql
you cannot way because inner select set you're deleting from.
basically you're creating table of table names , telling db delete it. iterating through them won't work without dynamic sql , exec
do need automate process?
what i've done in past this
select 'delete ' + tablename tablenames [conditions] your output this:
delete mytablename1 delete mytablename2 delete mytablename3 and copying results of query out of window , running them.
if need automate in sql can concatenate output strings in result , send them parameter exec call.
Comments
Post a Comment