4

I use PDW and I have query which creates a list of tables to be dropped.

Table Q :

TableName
---------
   a
   b
   c
   d
   e

a,b,c,d,e are the list of tables in the database which should be dropped.

I want to write a dynamic sql query which will drop the tables a to e listed in table Q without any human intervention.

Is it possible?

2
  • 3
    So the list of tables to drop is in another table? Something sounds like the design got derailed somewhere. And not really sure what you mean about no human intervention. At some level there has to be human intervention. Commented May 30, 2018 at 21:24
  • 1
    The path to your solution starts here. spaghettidba.com/2015/04/24/… Commented May 30, 2018 at 21:24

1 Answer 1

1

You can use the following dynamic sql to achieve this: (assuming that the table name is Table Q and the column name is TABLE_NAME)

DECLARE @strQuery as varchar(MAX)

SET @strQuery = ''

SELECT @strQuery = @strQuery + 'DROP TABLE [' + TABLE_NAME + '];' FROM [Table Q] 

EXEC(strQuery)
Sign up to request clarification or add additional context in comments.

1 Comment

Improvement: Let this is a job so there is no human intervention

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.