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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -